LeetCode-Remove Duplicates from Sorted Array-从有序数组移除重复-简单逻辑
生活随笔
收集整理的這篇文章主要介紹了
LeetCode-Remove Duplicates from Sorted Array-从有序数组移除重复-简单逻辑
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/
用一個cnt記錄不重復的部分,后面每遇到不重復的cnt++即可。
class Solution { public:int removeDuplicates(int A[], int n) {if (n==0) return 0;int last=A[0]-1;int count=1;for(int i=0;i<n;i++){if(A[count-1]!=A[i]) {A[count++]=A[i];}}return count;} };?
轉載于:https://www.cnblogs.com/yangsc/p/4036348.html
總結
以上是生活随笔為你收集整理的LeetCode-Remove Duplicates from Sorted Array-从有序数组移除重复-简单逻辑的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: nginx File not found
- 下一篇: 真恶心,用安卓模拟器开微信不能找附近的人