题目来源:https://leetcode.com/problems/remove-duplicates-from-sorted-array/
题目难度:Easy
解答1[Java]:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| class Solution { public int removeDuplicates(int[] nums) { if (nums.length == 0) return 0;
int head = 0; int tail = 0; for (; tail < nums.length; tail++) { if (nums[head] != nums[tail]) { nums[++head] = nums[tail]; } }
return head + 1; } }
|