Skip to content

Commit 5ac1564

Browse files
committed
26. Remove Duplicates from Sorted Array
1 parent b684b5c commit 5ac1564

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
3+
1. 아이디어 :
4+
문자열에서 중복된 원소를 빼고 재배치, 고유한 원소 크기 반환
5+
6+
2. 시간복잡도 : O(N)
7+
8+
3. 자료구조/알고리즘 : 완전탐색
9+
10+
*/
11+
12+
class Solution {
13+
public int removeDuplicates(int[] nums) {
14+
int prev = -200;
15+
int idx = 0;
16+
17+
// 오름차순
18+
for(int i : nums) {
19+
if(i == prev) continue;
20+
nums[idx++] = i;
21+
prev = i;
22+
}
23+
24+
return idx;
25+
}
26+
}

0 commit comments

Comments
 (0)