【LeetCode with Python】 Remove Duplicates from Sorted Array II
2014-09-21 17:47
477 查看
博客域名:http://www.xnerv.wang
原题页面:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array-ii/
题目类型:
难度评价:★
本文地址:/article/1377471.html
Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?
For example,
Given sorted array A =
Your function should return length =
原题页面:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array-ii/
题目类型:
难度评价:★
本文地址:/article/1377471.html
Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?
For example,
Given sorted array A =
[1,1,1,2,2,3],
Your function should return length =
5, and A is now
[1,1,2,2,3].
class Solution: # @param a list of integers # @return an integer def removeDuplicates(self, A): if None == A: return 0 len_A = len(A) if len_A <= 1: return len_A m = 0 n = 1 count = 1 while n < len_A: if A[m] != A : count = 1 m += 1 if m != n: A[m] = A elif count >= 2: count += 1 else: m += 1 count += 1 if m != n: A[m] = A n += 1 A = A[0:m+1] # A must be modified return m + 1
相关文章推荐
- 【LeetCode with Python】Remove Duplicates from Sorted Array II
- 【LeetCode with Python】 Remove Duplicates from Sorted Array
- 【LEETCODE】80-Remove Duplicates from Sorted Array II [Python]
- [leetcode]Remove Duplicates from Sorted Array II @ Python
- [Leetcode][python]Remove Duplicates from Sorted Array/Remove Duplicates from Sorted Array II
- [LeetCode]Remove Duplicates from Sorted Array II @python
- [LeetCode]题解(python):080-Remove Duplicates from Sorted Array II
- 【LeetCode with Python】 Remove Duplicates from Sorted List II
- [leetcode] python Remove Duplicates from Sorted Array II
- LeetCode:Remove Duplicates from Sorted Array I&&II
- LeetCode: Remove Duplicates from Sorted Array II
- [leetcode]Remove Duplicates from Sorted Array II
- LeetCode:Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- [leetcode]Remove Duplicates from Sorted Array II
- LeetCode - Remove Duplicates from Sorted Array II
- LeetCode-Remove Duplicates from Sorted Array II
- leetcode -- Remove Duplicates from Sorted Array II
- 【LeetCode with Python】 Remove Duplicates from Sorted List
- [Leetcode 30] 80 Remove Duplicates From Sorted Array II