문제로

내가 푼 것

틀림

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution {
    public int removeDuplicates(int[] nums) {
        Set<Integer> remover = new HashSet<>();

        for(int i = 0; i < nums.length; i++) {
            remover.add(nums[i]);
        }

        return remover.size();
    }
}
 
## 답안1
```java
class Solution {
    public int removeDuplicates(int[] nums) {
        int j = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] != nums[i - 1]) {
                nums[j] = nums[i];
                j++;
            }
        }
        return j;
    }
}

참고

배열도 수정해야 정답처리된다