728x90
https://leetcode.com/problems/remove-duplicates-from-sorted-array/
감소하지 않는 순서로 정렬된 nums 배열이 주어진다. 각 유니크한 요소들이 오직 한 번만 나타나도록 중복을 삭제해라.
input array를 수정하는 방식으로 해야됨. 중복 수를 제거하고나서 몇 개가 나오는지 출력해라.
STL vector에서 earse/unique를 사용하면 간편하다.
꼭 잊지 말고 기억하긔~~
int removeDuplicates(vector<int>& nums) {
nums.erase(unique(nums.begin(), nums.end()), nums.end());
return nums.size();
}
728x90
'알고리즘 > LeetCode' 카테고리의 다른 글
[LeetCode/easy/Array] Search Insert Position (0) | 2022.08.16 |
---|---|
[LeetCode/easy/Array] Remove Element (0) | 2022.08.16 |
[LeetCode/easy] Ransom Note (0) | 2022.08.12 |
[LeetCode/easy] Reverse Vowels of a String (0) | 2022.08.12 |
[LeetCode/easy] Word Pattern (0) | 2022.08.12 |