Medium 80题 Remove Duplicates from Sorted Array II
来源:互联网 发布:淘宝开店客服的子账号 编辑:程序博客网 时间:2024/05/16 15:28
Question:
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.
SOLUTION:
public class Solution { public int removeDuplicates(int[] nums) { int i=0; for(int j=0;j<=nums.length-1;j++) { if(i<2||nums[j]>nums[i-2]) { nums[i]=nums[j]; i++; } } return i; }}
0 0
- Medium 80题 Remove Duplicates from Sorted Array II
- [leetcode 80, Medium] Remove Duplicates from Sorted Array II
- LeetCode-80-Remove Duplicates from Sorted Array II(递归)-Medium
- 【Leet Code】80. Remove Duplicates from Sorted Array II---Medium
- Leetcode 80. Remove Duplicates from Sorted Array II (Medium) (cpp)
- 【Medium】80. Remove Duplicates from Sorted Array II
- leetcode80[medium]--Remove Duplicates from Sorted Array II
- 80 Remove Duplicates from Sorted Array II
- 80Remove Duplicates from Sorted Array II
- [80]Remove Duplicates from Sorted Array II
- 80Remove Duplicates from Sorted Array II
- 80 - Remove Duplicates from Sorted Array II
- LeetCode-Array-80 Remove Duplicates from Sorted Array II
- 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
- 如何检查IP是否为内网IP
- 动态规划之01背包问题
- Medium 139题 Word Break
- Medium 79题 Word Search
- 协变与逆变
- Medium 80题 Remove Duplicates from Sorted Array II
- 简单C# MVC 通信录,使用REST API 应用到 Azure (有源码)
- Missing Number
- Medium 50题 Pow(x, n)
- 大数据干货贴
- 申请微软Azure(云服务) 免费账号和安装Application Insight(网站健康监控)
- 一个REST API 在Azure上应用的简单通讯录例子。(C#, MVC)
- Java Notes: Java的抽象类和接口
- HBase Replication