Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 27 | 28 | 29 | 30 |
31 |
Tags
- Bit
- 순회
- sorting
- LinkedList
- bst
- Math
- 리스트
- 카카오
- traversal
- 2019 카카오
- 오픈 채팅방
- 트리
- 배열
- list
- Subset
- tree
- Linked List
- kakao
- 스택
- 정렬
- leetcode
- binary search tree
- Easy
- Medium
- 공채
- Bubble Sort
- stack
- 완전검색
Archives
- Today
- Total
미리수얌 블로그
LeetCode: Remove Duplicates from Sorted Array 본문
LeetCode: Remove Duplicates from Sorted Array
정렬된 배열이 주어졌을때 똑같은 숫자를 In-Place 로 없에고 길이를 리턴하시오.
예를 들어 [1, 1, 2, 3, 4, 5, 5, 6] 이 주어 졌으면 이것을
[1, 2, 3, 4, 5, 6, ?, ?] 로 바꾸고 (뒤에 ? 에는 무슨 숫자가 와도 무방) 그 다음 6 을 리턴.
다른 예로는 [1, 1, 1, 1, 2] => [1, 2, ?, ?, ?] 그리고 2를 리턴
public int removeDuplicates(int[] nums) {
if (nums.length == 0) return 0;
int noDupIndex = 1;
for (int i = 1; i < nums.length; ++i) {
if (nums[i] != nums[i - 1]) {
nums[noDupIndex++] = nums[i];
}
}
return noDupIndex;
}
'코딩문제풀이 > Leetcode' 카테고리의 다른 글
LeetCode: Remove Nth Node From End of List (0) | 2018.09.25 |
---|---|
LeetCode: Letter Combinations of a Phone Number (0) | 2018.09.25 |
Valid Parentheses (0) | 2018.09.25 |
Add Two Numbers (0) | 2018.09.23 |
Two Sum (0) | 2018.09.21 |
Comments