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.

 

 

给定一有序数组,删除所有重复元素,保证每个元素只出现一次,并返回新数组的长度。不能额外申请空间。如给定数组[1,1,2],处理后应返回长度2,数组的前两个元素分别为1,2。其中,剩余元素如何排序没有要求。

 

 

 

标签:

Move Zeroes

Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. For exa...

阅读全文

Odd Even Linked List

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not ...

阅读全文

八皇后问题与回溯算法

八皇后问题是在8*8的棋盘上放置8枚皇后,使得棋盘中每个纵向、横向、左上至右下斜向、右上至左下斜向均只有一枚皇后。八皇后的一个可行解如图所示: ...

阅读全文