leetcode之Remove Duplicates from Sorted List II
来源:互联网 发布:艾媒数据 招聘 编辑:程序博客网 时间:2024/05/21 19:30
class Solution {
public:
int removeDuplicates(int A[], int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(A==NULL||n<=0) {
return 0;
}
int index=0;
int pre=1;
bool dup=false;
while (index<n-1&&pre<=n-1) {
if (A[index]==A[pre]) {
if (!dup) {
//pre++;
A[++index]=A[pre];
pre++;
dup=true;
} else
// A[++index]=A[pre];
pre++;
}
else{
A[++index]=A[pre];
pre++;
dup=false;
}
}
return index+1;
}
};
public:
int removeDuplicates(int A[], int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(A==NULL||n<=0) {
return 0;
}
int index=0;
int pre=1;
bool dup=false;
while (index<n-1&&pre<=n-1) {
if (A[index]==A[pre]) {
if (!dup) {
//pre++;
A[++index]=A[pre];
pre++;
dup=true;
} else
// A[++index]=A[pre];
pre++;
}
else{
A[++index]=A[pre];
pre++;
dup=false;
}
}
return index+1;
}
};
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode]Remove Duplicates from Sorted List II
- [leetcode]Remove Duplicates from Sorted List II
- LeetCode-Remove Duplicates from Sorted List II
- [leetcode] Remove Duplicates from Sorted List II
- LeetCode - Remove Duplicates from Sorted List II
- LeetCode | Remove Duplicates from Sorted List II
- LeetCode:Remove Duplicates from Sorted List II
- 【leetcode】Remove Duplicates from Sorted List II
- Leetcode: Remove Duplicates from Sorted List II
- leetcode Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- hdu 1548(2013.9.15周赛F题BFS)
- JSP的多线程问题详解
- maven axis2 的pom.xml 配置
- 关于图像多尺度的一些基础知识
- POJ 3261 Milk Patterns (后缀数组或HASH,4级)
- leetcode之Remove Duplicates from Sorted List II
- CodeForces 165C - Another Problem on Strings
- div中的相对定位与绝对定位(转)
- 【Leetcode】Triangle
- VC字符串与整数、浮点数、无符号整数之间的转换常用函数
- 乐观锁与悲观锁
- 系统学习Linux的11点建议
- 设计模式C++实现(3)——适配器模式
- android基础6——设置圆角按钮