There is some problem in the last for loop.


  • 0
    X

    public class Solution {
    public int removeDuplicates(int[] A) {

        if (A.length = 0){
            return 0;
        }
        
        Map<Integer,Integer> map= new HashMap<Integer,Integer>();
        
        Map<Integer,Integer> map1= new HashMap<Integer,Integer>();
        
        for (int i = 0; i<A.length; i++){
            int length =1;
            if (!map.containsValue(A[i])){
                map.put(i,A[i]);
            }
            
            if (map.containsValue(A[i])){
                if (!map1.containsValue(A[i])){
                    map1.put(i, A[i]);
                }
            }
        }
        
        // map1 only contains the memeber exist not above twice
        int j =0;
        for (int i = 0; i<A.length; i++){
            if (map.containsKey(i)){
                A[j] = map.get(i);
                j++;
            }
            if (map1.containsKey(i)){
                A[j] = map1.get(i);
                j++;
            }
        }
        
        return j;
    }
    

    }


Log in to reply
 

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