What's wrong with my code(using JAVA)


  • 0
    I
    public class Solution {
        public int removeElement(int[] A, int elem) {
            List<Integer> B = new ArrayList<Integer>();
            int len = A.length;
            int j = 0;
            for(int i=0;i<len;i++){
                if(A[i]!= elem){
                    B.add(A[i]);
                    j++;
                }
            }
            
            return j;
        }
    }

  • 0
    T

    you cannot create a new list<Integer>B


Log in to reply
 

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