Why Runtime Error with Last executed input: [1], 1


  • 0
    R
    public class Solution {
        public int removeElement(int[] A, int elem) {
            
            if(A.length == 0) return 0;
            
            HashSet<Integer> uniqElems = new HashSet<>();
            
            for(int i = 0; i < A.length; i++) {
                if(!uniqElems.contains(A[i])) {
                    uniqElems.add(A[i]);
                }
            }
            
            Iterator<Integer> itr = uniqElems.iterator();
            int j = 0;
            while(itr.hasNext()) {
                A[j++] = (Integer)itr.next().intValue();
            }
            
            return j + 1;
            
        }
    }

Log in to reply
 

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