You do ask to return "the new length", right?


  • 1
    S

    Input: [3,3], 5

    Output: [3,3,0]

    Expected: [3,3]

    So I don't understand, what does this mean...


  • 0
    F

    I think this is kind of bug about the answer lc wrote down and the answer lc really want. Lots of question similiar like this, you cant simply return the length, also the new array should be correct as well.


  • 0
    W

    I met the same problem. the return is a array. Why?
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < A.length; i++) {
    list.add(A[i]);
    }

     Iterator<Integer> iter = list.iterator();
    
     while (iter.hasNext()) {
    	int temp = iter.next();
    	if (temp == elem) {
    		iter.remove();
    	}
    }
    
     System.out.println(list.size());
     System.out.println(list);
     return list.size();

Log in to reply
 

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