*LeetCode-Remove Duplicates from Sorted Array
来源:互联网 发布:压缩感知 知乎 编辑:程序博客网 时间:2024/06/05 17:14
蠢哭了要 还想着每次遇到重复都把整个数组移一遍,不用啊!两个指针一个在现在无重复区域的末尾,一个在还没判断的区域的头,只要不一样就挪这一位,一样就不管,最后返回无重复区域的index+1不就是length勒马
public class Solution { public int removeDuplicates(int[] A) { if ( A == null || A.length == 0 ) return 0; int pos = 1; for ( int i = 1; i < A.length; i ++ ){ if ( A [i] != A [pos-1] ){ A [pos] = A[i]; pos ++; } } return pos; }}
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
- 设计模式之装饰模式
- Jackson解析工具简单应用
- Jackson使用实例
- LeetCode-Valid Sudoku
- Cocos2d-x 3.2 大富翁游戏项目开发-单机开发结束
- *LeetCode-Remove Duplicates from Sorted Array
- 流媒体简介
- How to Add a Dotted Underline Beneath HTML Text
- Longest Palindromic Substring
- NP完全性理论与近似算法——TSP问题为例
- better Life, better Apple, better Technology, better Style
- ArcGIS Runtime SDK for iOS之利用代码添加图层(Layers)
- [phone]找连续字符组成的substring的组成char
- 简单几步让CentOS系统时间同步