Java use bloom solution beats 96%


  • 0
    F
    public List<Integer> findDisappearedNumbers(int[] nums) {
           //  for (int i = 0; i < nums.length; i++) {
           //      int val = Math.abs(nums[i]) - 1;
           //      if (nums[val] > 0) {
           //          nums[val] = -nums[val];
           //      }
           //  }
           //  List<Integer> result = new ArrayList<Integer>();
           //  for (int i = 0; i < nums.length; i++) {
           //      if (nums[i] > 0) {
           //          result.add(i + 1);
           //      }
           //  }
           //  return result;
           boolean[] bloom = new boolean[nums.length];
           for (int n : nums) {
               bloom[n-1] = true;
           }
           List<Integer> result = new ArrayList<Integer>();
           for (int i = 0; i < bloom.length; i++) {
               if (!bloom[i]) {
                   result.add(i+1);
               }
           }
           return result;
       }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.