# LeetCode OJ 系列之26 Remove Duplicates from Sorted Array --Python

Problem:

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) == 0: return len(nums)
last = nums[-1]
for index in range(len(nums)-2,-1,-1):
if last == nums[index]: del nums[index]
else: last = nums[index]
return len(nums)
Note:

class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
return len(set(nums))

#### LeetCode 26 — Remove Duplicates from Sorted Array（C++ Java Python）

2014-02-23 15:12:20

#### LeetCode --- 26. Remove Duplicates from Sorted Array

2015-02-02 11:52:37

#### Remove Duplicates from Sorted Array -- LeetCode

2014-02-27 05:12:22

#### Remove Duplicates from Sorted Array II -- LeetCode

2014-04-23 08:39:29

#### Remove Duplicates from Sorted Array [python解]

2017-07-24 19:18:55

#### 26. Remove Duplicates from Sorted Array (python)

2016-10-30 15:58:23

#### LeetCode:Remove Duplicates from Sorted Array

2013-09-02 20:42:03

#### Leetcode_26_Remove Duplicates from Sorted Array

2014-11-27 23:21:40

#### [C++]LeetCode 26: Remove Duplicates from Sorted Array（有序数组去重）

2015-05-02 21:43:54

#### [leetcode-26]Remove Duplicates from Sorted Array(C)

2015-07-28 12:36:07