Why doesn't this work?


  • 0
    Y

    This doesn't work?

    public List<Integer> findDisappearedNumbers(int[] nums) {
        ArrayList<Integer> res = new ArrayList<Integer>();
        boolean c = false;
        for (int i = 1; i <= nums.length; i++) {
            for (int j = 0; j < nums.length; j++)
                if (nums[j] == i)
                    c = true;
            if (!res.contains(i) && c == false)
                res.add(i);
            c = false;
        }
        return res;

  • 0
    A

    I haven't checked the code itself but they need O(N) complexity & this is O(N^2).


Log in to reply
 

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