80. Remove Duplicates from Sorted Array II
来源:互联网 发布:淘宝天猫美工 编辑:程序博客网 时间:2024/06/05 04:23
Follow up for “Remove Duplicates”:
What if duplicates are allowed at most twice?
For example,
Given sorted array nums = [1,1,1,2,2,3],
Your function should return length = 5, with the first five elements of nums being 1, 1, 2, 2 and 3. It doesn’t matter what you leave beyond the new length.
class Solution { public int removeDuplicates(int[] nums) { // write your code here if(nums == null) return 0; int cur = 0; int i ,j; for(i = 0; i < nums.length;){ int now = nums[i]; for( j = i; j < nums.length; j++){ if(nums[j] != now) break; if(j-i < 2) nums[cur++] = now; } i = j; } return cur; }}
阅读全文
0 0
- 80. Remove Duplicates from Sorted Array II
- 80.Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- 80. Remove Duplicates from Sorted Array II
- oracleの知識ポイント
- 数据结构 — 快速排序
- nginx tar.gz安装方法+简单静态文件配置
- Spring源码阅读(三)—IOC容器依赖注入
- Ubuntu编译Android源码过程中的空间不足解决方法
- 80. Remove Duplicates from Sorted Array II
- 动态规划专项训练(1)
- Spring Data详解
- Python 爬取百度词条Python Demo
- JAVA 定时激活程序代码
- RNTI
- poj1011:Sticks
- VPC使用SNAT实现内网机器可以使用互联网
- 你好:MineData