Remove Duplicates from Sorted Array II
来源:互联网 发布:听力软件 编辑:程序博客网 时间:2024/05/19 11:44
public class Solution { public int removeDuplicates(int[] A) { int count = 0; int tmp = 0; if(A == null || A.length == 0){ return 0; } if(A.length == 1){ return 1; } int pivot = A[0] - 1; int compare = A[0]; for(int i = 1 ; i < A.length ; i++){ if(A[i] == compare){ if(tmp > 0){ A[i] = pivot; count++; } tmp++; }else{ compare = A[i]; //A[i - count] =A[i]; tmp = 0; } } int index = 0; for(int i = 0 ; i < A.length ; i++){ if(A[i] == pivot){ index++; }else{ A[i - index] = A[i]; } } return A.length - count; }}
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
- WordPress 3.9使用PostgreSQL数据库问题的解决
- 使用KeyChain保存和获取UDID(唯一标示)
- MyBatis学习之三--动态SQL语句
- 【python 编程】网页中文过滤分词及词频统计
- c++ 单例模式
- Remove Duplicates from Sorted Array II
- C#关键字-where(泛型类型约束)
- 程序员总结:帮助你早些明白一些道理
- pager-lib实现分页
- java socket例子
- 编写webservice服务端和客户端实例(1)
- Twitter创始人回忆创业艰辛:梦里为房租发愁
- C# vs2010编译时filetracker:error ftk1011
- UIWindow和UIView