Compare commits
2 Commits
d38af5164a
...
8bd3a3b7a3
| Author | SHA1 | Date | |
|---|---|---|---|
| 8bd3a3b7a3 | |||
| 7e82ef55c0 |
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,9 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class test {
|
||||
public static void main(String[] args) {
|
||||
int[] nums = new int[]{3,2,2,3,1,2};
|
||||
int[] nums1 = new int[]{1,2,3,0,0,0};
|
||||
int length = Solution.removeElement(nums,3);
|
||||
int[] nums = new int[]{1,2,3,4,4,5,6};
|
||||
Solution.removeDuplicates(nums);
|
||||
System.out.println(nums);
|
||||
System.out.println(length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user