0
0

More than 1 year has passed since last update.

Leetcode 268. Missing Number

Posted at

268. Missing Number

難易度

Easy

アプローチ

Hashmap

class Solution {
    public int missingNumber(int[] nums) {

       HashMap<Integer,Boolean> hashmap = new HashMap<>();

        for(int i = 0 ; i <= nums.length ; i++){
            hashmap.put(i, false);
        }

        Arrays.stream(nums).forEach(obj -> {
            hashmap.put(obj, true);
        });

        return hashmap.entrySet().stream()
                .filter(obj -> obj.getValue() == false)
                .findFirst()
                .get()
                .getKey();
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0