Remove Duplicates from Sorted Array II
来源:互联网 发布:手机垃圾清理软件 编辑:程序博客网 时间:2024/06/06 09:55
思路:加入一个变量来记录元素出现的次数
方法一:class A{public: int Remove(int *a,int len) { if(a==NULL||len<0) return 0; if(len<=2) return len; int index=2; for(int i=2;i<len;i++){ if(a[i]!=a[i-2]){ index++; a[index]=a[i]; } } return index; }};方法二:class B{public: int Remove(int *a,int len){ if(a==NULL||len<0) return 0; int index=0; for(int i=0;i<len;i++){ if(i>0 && i<n-1 && a[i]==a[i-1] && a[i]=a[i+1]) countinue;//调到for循环,对于break直接跳出for循环 a[index]=a[i]; index++; } return index; }};
0 0
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- [leetcode] Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- Remove duplicates from sorted array II
- Remove Duplicates from Sorted Array II
- [LeetCode]Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- [leetcode]Remove Duplicates from Sorted Array II
- LeetCode-Remove Duplicates from Sorted Array II
- 64位Ubuntu上编译32位程序操作步骤
- mysql 主主+主从笔记
- day08 广播与服务(二)
- 个人开源项目doMoreDoBetter
- BZOJ 1041: [HAOI2008]圆上的整点
- Remove Duplicates from Sorted Array II
- blog need to read
- SpringMVC系列之(一) 入门实例
- 求图的顶点连通度和边连通度
- QT Creator 代码自动补全---快捷键设定
- java 中E T ?使用
- Java 使用stringTemplate导出大批量数据excel(百万级)
- org.eclipse.swt.SWTError: No more handles解决方法
- 携程Android App插件化和动态加载实践