This commit is contained in:
kkunkka
2023-12-15 23:46:22 +08:00
parent d6bec129e9
commit 781a17e31e
2 changed files with 36 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
package com.dota.arr._26;
/**
* 26. 删除有序数组中的重复项
*/
public class Solution {
public int removeDuplicates(int[] nums) {
int i = 0;
int j = 1;
while (j < nums.length) {
if (nums[j] != nums[i]) {
nums[++i] = nums[j];
}
j++;
}
return i + 1;
}
}

View File

@@ -0,0 +1,17 @@
package com.dota.arr._27;
/**
* 27. 移除元素
*/
class Solution {
public int removeElement(int[] nums, int val) {
int i = 0;
for (int j = 0; j < nums.length; j++) {
if (nums[j]!=val) {
nums[i++] = nums[j];
}
}
return i+1;
}
}