LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
📌 - 의사코드
📌- 풀이
- count를 1로 두고 for문을 수행하면서 이전 배열과 다를 경우에 count값에 num[i]값을 넣어주고 count++
🔥 - Java 코드
class Solution {
public int removeDuplicates(int[] nums) {
int count =1;
for(int i=1; i<nums.length;i++){
if(nums[i-1] != nums[i]){
nums[count++] = nums[i];
}
}
return count;
}
}