leetcode
来源:互联网 发布:sql union join的区别 编辑:程序博客网 时间:2024/06/05 02:59
26. Remove Duplicates from Sorted Array
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.
Subscribe to see which companies asked this question
找出第一个与前一个数字不同的数字
class Solution {public: int removeDuplicates(vector<int>& nums) { if(nums.empty()) return 0; int index=0,i=1; for(;i<nums.size();i++) { if(nums[index]!=nums[i]) nums[++index]=nums[i]; } return index+1; }};
0 0
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode:
- leetcode
- mysql中的if条件语句用法
- css生成斜纹样式
- 2016.02.01技术成长思考
- mongodb word 笔记
- 自己动手构建的超级计算机-----建立树莓派集群
- leetcode
- 11g单实例数据库打最新11.2.0.4.160119 PSU补丁记录
- TensorFlow 基本使用
- angular中运用$cacheFactory服务时候报错
- PullToRefreshListView的漏洞
- 利用kali 的arp欺骗获取靶机的图片方法与arp断网
- Protocol Buffer技术详解(C++实例)
- postgresql分类排序后取某一类记录的前n条
- 【慕课笔记】U2 封装 第1节 什么是JAVA中的封装