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();
}
}