LeetCode:Remove Duplicates from Sorted Array
来源:互联网 发布:mac系统重装的网络加速 编辑:程序博客网 时间:2024/06/05 09:54
1.
class Solution {public: int removeDuplicates(int A[], int n) { if(n==0) return 0; int index = 0; for(int i = 1;i<n;i++){ if(A[index]!=A[i]) A[++index] = A[i];} return index+1; }};
2.
class Solution { public: int removeDuplicates(int A[], int n) { if (n == 0) return 0; int slow(1), fast(1); while(fast < n){ while(fast < n && A[fast] == A[fast-1]) fast++; if (fast < n) A[slow++] = A[fast++]; } return slow; }};
思路都是一样的
一直往后找不等于前面的数 然后赋值
0 0
- [leetcode][array] Remove Duplicates from Sorted Array
- 【Leetcode】【Array】Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array
- [Leetcode] Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- leetcode 35: Remove Duplicates from Sorted Array
- [LeetCode] Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array
- Leetcode: Remove Duplicates from Sorted Array
- [leetcode] Remove Duplicates from Sorted Array II
- [LeetCode]Remove Duplicates from Sorted Array
- [LeetCode]Remove Duplicates from Sorted Array II
- [leetcode]Remove Duplicates from Sorted Array
- [leetcode]Remove Duplicates from Sorted Array II
- c++学习网站
- Fiddler抓包工具
- 各种嵌入式操作系统介绍
- AWS、Azure、Google云 谁的免费层更好?
- opencv cmake找不到ffmpeg动态包的问题
- LeetCode:Remove Duplicates from Sorted Array
- 自定义校验型注解
- 消息认证码MAC-Message Authentication Code
- 大白话讲解Promise(一)
- js实现滑动门效果
- VisualStudio2015密钥
- [python3教程]第十二章.虚拟环境和程序集(VIRVUAL ENVIRONMENTS AND PACKAGES)
- Codeforecs 785C Anton and Fairy Tale 数学+二分
- Cython的安装