算法练习(23) leetcode 26. 删除排序数组中的重复项

tech2024-02-21  73

https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/

class Solution { public int removeDuplicates(int[] nums) { if(nums.length==0) { return 0; } int num=nums[0],location=1; for (int i=1;i< nums.length;i++) { if(nums[i]!=num) { num=nums[i]; nums[location]=num; location++; } } return location; } }

 

最新回复(0)