LeetCode(26) Remove Duplicates from Sorted Array
来源:互联网 发布:windows引导修复工具 编辑:程序博客网 时间:2024/06/05 00:52
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 int removeDuplicates(int[] nums) { int index = 0; if(nums.length == 0) return 0; for(int i = 1; i < nums.length; i++){ if(nums[index] != nums[i]) nums[++index] = nums[i]; } return index+1; }
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
- 如何下载谷歌/百度/高德大字体地图用于打印
- 数据迁移工具-SSIS和Spoon 区别简介 -从浅入深(2.控件的基本用法)
- 【Bzoj 2434】[NOI 2011] 阿狸的打字机
- iOS应用中如何声明全局变量?
- 开发与研发
- LeetCode(26) Remove Duplicates from Sorted Array
- 手把手教你画太极图
- 从福昕阅读器转回到adobe reader
- el表达式
- python matplotlib中文显示问题
- C#中的异常语句
- 手把手教你画太极图
- 2416开发记录七: platform驱动之LED(misc)
- 位运算