• 문제 링크
Remove Duplicates from Sorted Array - LeetCode
Can you solve this real interview question? Remove Duplicates from Sorted Array - Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place [https://en.wikipedia.org/wiki/In-place_algorithm] such that each unique element ap
leetcode.com
• 풀이 코드
public class Solution {
public int removeDuplicates(int[] nums) {
if (nums.length == 1) return 1;
int idx = 1;
for (int i = 1; i < nums.length; i++) if (nums[i - 1] != nums[i]) nums[idx++] = nums[i];
return idx;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 28. Find the Index of the First Occurrence in a String - Java (0) | 2026.05.16 |
|---|---|
| [LeetCode] 27. Remove Element - Java (0) | 2026.05.15 |
| [LeetCode] 21. Merge Two Sorted Lists - Java (0) | 2026.05.13 |
| [LeetCode] 20. Valid Parentheses - Java (0) | 2026.05.12 |
| [LeetCode] 14. Longest Common Prefix - Java (0) | 2026.05.11 |
댓글