Compare commits
No commits in common. "8bd3a3b7a374f54be60b093131a44e9b4b9a7eef" and "d38af5164a5ba336907c8fc1573dc0a70e0ab1dc" have entirely different histories.
8bd3a3b7a3
...
d38af5164a
|
|
@ -175,18 +175,8 @@ public class Solution {
|
||||||
*/
|
*/
|
||||||
public static int removeDuplicates(int[] nums) {
|
public static int removeDuplicates(int[] nums) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (int j = 0; j < nums.length; j++) {
|
int[] newNums = new int[nums.length];
|
||||||
if (j == 0){
|
Map<Integer,Integer> duplicates = new HashMap<>();
|
||||||
nums[i] = nums[j];
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int preValue = nums[j - 1];
|
|
||||||
if (nums[j] != preValue){
|
|
||||||
nums[i] = nums[j];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,11 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class test {
|
public class test {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int[] nums = new int[]{1,2,3,4,4,5,6};
|
int[] nums = new int[]{3,2,2,3,1,2};
|
||||||
Solution.removeDuplicates(nums);
|
int[] nums1 = new int[]{1,2,3,0,0,0};
|
||||||
|
int length = Solution.removeElement(nums,3);
|
||||||
System.out.println(nums);
|
System.out.println(nums);
|
||||||
|
System.out.println(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue