26. Remove Duplicates from Sorted Array
来源:互联网 发布:画logo的软件 编辑:程序博客网 时间:2024/06/18 14:22
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.
code
class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
# for x in nums:
# if nums.count(x)>1:
# for i in range(nums.count(x)-1):
# nums.remove(x)
# return len(nums)
nums[:]=list(set(nums))
nums.sort()
return len(nums)
- [LeetCode]26.Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- LeetCode 26. Remove Duplicates from Sorted Array
- LeetCode --- 26. Remove Duplicates from Sorted Array
- LeetCode 26.Remove Duplicates from Sorted Array
- [Leetcode] 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 【leetcode】26. Remove Duplicates from Sorted Array
- 【leetcode】 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- [leetCode]26. Remove Duplicates from Sorted Array
- LeetCode 26.Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array LeetCode
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- Shell的种类
- linux 查看一个文件或一个文件夹大小
- openssl、x509、crt、cer、key、csr、ssl、tls 这些都是什么鬼?
- USACO——Closing the farm
- 关于ImageLoader must be init with configuration before using问题解决
- 26. Remove Duplicates from Sorted Array
- 关于Servlet的几个小问题
- WIN32学习——资源学习
- delegate协议实现一对多
- 图(二叉树)邻接矩阵(数组描述)
- 树与二叉树
- 解决utunbu无法在线播放音乐的问题
- 按学生成绩进行升序排列
- Highcharts简介