Leetcode 26 Remove Duplicates from Sorted Array
来源:互联网 发布:金投顾软件 编辑:程序博客网 时间:2024/06/06 15:02
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
For example,
Given input array nums = [1,1,2]
,
Your function should return length = 2
, with the first two elements of nums being 1
and 2
respectively. It doesn't matter what you leave beyond the new length.
public class Solution { public int removeDuplicates(int[] nums) { int original = nums.length; int j =1; for(int i = 1; i<original;i++){ if(nums[i] != nums[i-1]){ nums[j++] = nums[i]; } } return j; }}
没什么特别要说的/。。。就是记得看清楚是不是修改原数组
0 0
- 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
- 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
- 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
- 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
- leetcode[26]:Remove Duplicates from Sorted Array
- leetcode 26 Remove Duplicates from Sorted Array
- angularJs中filter的用法及api解释
- 每次maven-update project ,又变成compile level变为1.5解决方法
- 微信小程序开发之本地图片上传(leancloud)
- Spring boot集成Mybatis
- IDEA15 配置使用
- Leetcode 26 Remove Duplicates from Sorted Array
- SwissArmyKnife调试Android UI的工具
- Android 检索相册视频文件
- 前缀、中缀、后缀表达式(逆波兰表达式)
- L版本AAL
- git 常用命令 创建查看删除分支,创建查看删除tag等
- 快播团队悄然崛起:连获2大奖,业内充分肯定,抢先布局千亿市场
- 微信小程序开发之真机测试 地图定位 map API 无法获取当前位置的问题
- PS学习基础案例