更新 Solution.java
This commit is contained in:
@@ -175,8 +175,18 @@ public class Solution {
|
||||
*/
|
||||
public static int removeDuplicates(int[] nums) {
|
||||
int i = 0;
|
||||
int[] newNums = new int[nums.length];
|
||||
Map<Integer,Integer> duplicates = new HashMap<>();
|
||||
|
||||
for (int j = 0; j < nums.length; j++) {
|
||||
if (j == 0){
|
||||
nums[i] = nums[j];
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
int preValue = nums[j - 1];
|
||||
if (nums[j] != preValue){
|
||||
nums[i] = nums[j];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user