You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
372 B
22 lines
372 B
package class28;
|
|
|
|
public class Problem_0026_RemoveDuplicatesFromSortedArray {
|
|
|
|
public static int removeDuplicates(int[] nums) {
|
|
if (nums == null) {
|
|
return 0;
|
|
}
|
|
if (nums.length < 2) {
|
|
return nums.length;
|
|
}
|
|
int done = 0;
|
|
for (int i = 1; i < nums.length; i++) {
|
|
if (nums[i] != nums[done]) {
|
|
nums[++done] = nums[i];
|
|
}
|
|
}
|
|
return done + 1;
|
|
}
|
|
|
|
}
|