code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

Duplicatesinarray

/**
 *
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

import java.util.HashMap;

class DuplicatesInArray {

  static void func(int[] nums){
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    for(int i = 0; i < nums.length; i++){
      if(map.get(nums[i]) == null){
        System.out.println(nums[i]);
      }
      map.put(nums[i], 0);
    }
  }

  public static void main(String[] args){
    int[] nums = {10, 20, 20, 30, 30, 30};
    func(nums);
  }
}

Created 2021-10-27T02:53:48+01:00 · Edit