[leetcode刷题] Remove Duplicates from Sorted Array
来源:互联网 发布:开淘宝店后要怎么操作 编辑:程序博客网 时间:2024/06/07 22:53
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
For example,
Given input array nums = [1,1,2]
,
Your function should return length = 2
, with the first two elements of nums being 1
and 2
respectively. It doesn't matter what you leave beyond the new length.
class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if len(nums) <= 1: return len(nums) else: left = 0 right = left + 1 length =len(nums) - 1 while right < length: if nums[left] == nums[right]: temp = right nums.pop(right) right = temp length = len(nums)-1 else: left += 1 right += 1 if nums[left] == nums[right]: nums.pop(right) return len(nums)
0 0
- [leetcode刷题] Remove Duplicates from Sorted Array
- [leetcode][array] Remove Duplicates from Sorted Array
- 【Leetcode】【Array】Remove Duplicates from Sorted Array
- LeetCode刷题【Array】 Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array
- [Leetcode] Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- leetcode 35: Remove Duplicates from Sorted Array
- [LeetCode] Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array
- Leetcode: Remove Duplicates from Sorted Array
- [leetcode] Remove Duplicates from Sorted Array II
- [LeetCode]Remove Duplicates from Sorted Array
- [LeetCode]Remove Duplicates from Sorted Array II
- 双击返回键退出应用程序的方法
- 2017-3月- 工作-随想
- spring事务原理
- 1
- jumpserver 堡垒机环境搭建(图文详解)
- [leetcode刷题] Remove Duplicates from Sorted Array
- php算俩个时间戳相差多少
- Android加载新项目Building时间久
- XGBoost Stopping to Avoid Overfitting(early_stopping_rounds )
- 人脸检测和人脸识别方法的比较
- MAC上NTFS格式移动硬盘的读写问题
- pcl通过积分图来进行法线预测
- SQL 条件语句的执行顺序
- 强化学习读书笔记