Given a sorted array, remove the duplicates in place such, all element appear only once and return the new L Ength.
Do the allocate extra space for another array, and you must does this on place with constant memory.
for example,
given input Array nums = [1,1,2]
,
your function should return length = 2
, with the first and elements Of nums Being 1
and 2
respectively. It doesn ' t matter what are you leave beyond the new length.
Subscribe to see which companies asked this question
Problem Solving Analysis:
The problem here is simple, remove the duplicate data, and then return to the length of the weight.
#-*-Coding:utf-8-*-__author__ = ' Jiuzhang ' class solution (object): def removeduplicates (self, nums): L = Len ( nums) i = 0 while i < L-1: if nums[i] = = nums[i + 1]: del nums[i + 1 ] L-= 1 Else: i + = 1 return L
(Leetcode) Remove duplicates from Sorted Array---ordered list de-weight