26. Remove Duplicates from Sorted Array
来源:互联网 发布:ae软件苹果版 编辑:程序博客网 时间:2024/06/10 17:03
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) { if(nums.length == 0) return nums.length; int j = 0; for(int i=1; i<nums.length; i++){ if(nums[i] != nums[j]){ j++; nums[j] = nums[i]; } } return j+1; }}
阅读全文
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
- 版式设计中如何做到均匀的版面
- JDBC与Mysql数据库的连接具体过程
- mysql安装好后调整my.cnf
- nginx 配置结合tomcat
- python socket.error: [Errno 10054] 远程主机强迫关闭了一个现有的连接。
- 26. Remove Duplicates from Sorted Array
- Axure RP 8.0 Mac中文破解版
- Tomcat安装和优化实战
- 算法谜题24 国际象棋棋盘着色问题
- spring所有模块头信息
- github 简单的上传远程仓库
- layer.js,,,分享一个好用的弹出层
- POJ3279 Fliptile题解 二进制枚举搜索法
- 分针网—每日分享:安装使用Mongoose配合Node.js操作MongoDB的基础教程