26. Remove Duplicates from Sorted Array
来源:互联网 发布:初唐网络 编辑:程序博客网 时间:2024/06/07 02:17
题目:https://leetcode.com/problems/remove-duplicates-from-sorted-array/
代码:
public class Solution { public int removeDuplicates(int[] nums) { if(nums.length==0) return 0; int new_length = nums.length; int i=0; while(i<new_length-1) { if(nums[i]==nums[i+1]) { new_length--; remove(nums,i); continue; } i++; } return new_length; } public void remove(int[] nums,int i) { for(int j=i;j<nums.length-1;j++) { nums[j] = nums[j+1]; } }}91ms!!!beat 1.47%bad code!!!!!!=============================修改===============public class Solution { public int removeDuplicates(int[] nums) { int i=0; for(int n:nums) { if(i<1||n>nums[i-1]) nums[i++] = n; } return i; }}1ms
0 0
- [LeetCode]26.Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- LeetCode 26. Remove Duplicates from Sorted Array
- LeetCode --- 26. Remove Duplicates from Sorted Array
- LeetCode 26.Remove Duplicates from Sorted Array
- [Leetcode] 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 【leetcode】26. Remove Duplicates from Sorted Array
- 【leetcode】 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- [leetCode]26. Remove Duplicates from Sorted Array
- LeetCode 26.Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array LeetCode
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 怎么用EDIUS将静帧图片做出动态特效
- label 显示不同颜色 不同文字点击事件
- React + Redux
- PHP排序详解
- Python爬虫实战(2):爬取京东商品列表
- 26. Remove Duplicates from Sorted Array
- mysql 5.7 安装问题
- 2.URL
- 利用git hook每次commit时执行一些其它操作。
- Collections sort 实体类排序
- RecyclerView超简单demo(局部更新取代ListView)
- Android异步任务AsyncTask使用详解
- 118. Pascal's Triangle
- mysql 查询表结构SQL