Remove Duplicates from Sorted Array
来源:互联网 发布:mdf文件用mysql打开 编辑:程序博客网 时间:2024/05/03 01:16
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.
即从一个已经排序的数组中删除重复的数字。
class Solution { public int removeDuplicates(int[] nums) { if(nums.length==0) return 0; int j=0; for(int i=1;i<nums.length;i++){ if(nums[j]!=nums[i]){ j++; nums[j]=nums[i];//记住此处是如何改变数组的值的。 } } return j+1; }}
阅读全文
0 0
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates From Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- 如何使用RedisTemplate访问Redis数据结构
- HDOJ2017_字符串统计
- 数独
- leetcode dp题目:
- 范数(Norm)和谱半径(Spectral Radii)
- Remove Duplicates from Sorted Array
- cocos2dx 开启控制台
- 【MongoDB】复制集 相关 (bully算法)
- html清除浮动的几种方法
- JAVA工程师学习路线
- [siggraph17]bungie的特效系统
- Unity3D三维坐标(X,Z轴)下物体拖动移动(贴地面移动)实现并实现物体碰撞检测
- CSS整理
- C++成员函数指针的应用