[Leetcode]Remove Duplicates from Sorted Array
来源:互联网 发布:通风管道设计绘制软件 编辑:程序博客网 时间:2024/06/06 03:17
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 A = [1,1,2]
,
Your function should return length = 2
, and A is now [1,2]
.
这题跟Remove Element那题类似, 解法也是差不多的~
class Solution: # @param a list of integers # @return an integer def removeDuplicates(self, A): if A is None or len(A) == 0: return 0 k = 1 for i in xrange(1, len(A)): if A[i] == A[i - 1]: continue A[k] = A[i] k += 1 return k
0 0
- [leetcode][array] Remove Duplicates from Sorted Array
- 【Leetcode】【Array】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
- 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
- [leetcode]Remove Duplicates from Sorted Array
- [leetcode]Remove Duplicates from Sorted Array II
- Scramble String
- Ansi、Unicode、UTF8字符串之间的转换和写入文本文件
- 解决android4.0后版本EditText边框不全显示的问题
- 实模式、保护模式和虚拟8086模式
- zigbee协议及开发(4)- 基础知识
- [Leetcode]Remove Duplicates from Sorted Array
- OPENWRT的串口初试
- unicode编码
- 数据库编程实战---经验心得
- 80x86 CPU 的工作模式(扫盲贴)
- 不同类型元素的并查集操作
- python ImportError: No module named 的问题
- 嵌入式如何入门
- zz-tiny210-sd卡烧写141029c