LeetCode26-删除有序数组中的重复项

LeetCode26-删除有序数组中的重复项

1
2
3
4
5
6
7
8
9
10
public int removeDuplicates(int[] nums) {
int n = nums.length;
int j = 0;
for (int i = 0; i < n; i++) {
if (nums[i] != nums[j]) {
nums[++j] = nums[i];
}
}
return j + 1;
}

LeetCode26-删除有序数组中的重复项
https://www.gravity.wang/2022/03/28/leetcode26/
Author
Gravity
Posted on
March 28, 2022
Licensed under