【LeetCode OJ】Remove Duplicates from Sorted Array

题目:Given a sorted array, remove the duplicates in place such that each element appear onlyonceand 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].

class Solution {public:int removeDuplicates(int A[], int n) {if(!n)return NULL;int i,num=1;for(i=1;i<n;i++){if(A[i]!=A[i-1]){A[num++]=A[i];}}return num;}};

,青春一经典当即永不再赎

【LeetCode OJ】Remove Duplicates from Sorted Array

相关文章:

你感兴趣的文章:

标签云: