26. Remove Duplicates from Sorted Array
来源:互联网 发布:程序员 南图 借书 编辑:程序博客网 时间:2024/05/17 22:59
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 == null || nums.length ==0) {return 0;} int newLength=0; List<Integer> newArray = new ArrayList<Integer>(); for(int i=0; i<nums.length; i++) { if(!newArray.contains(nums[i])) { newArray.add(nums[i]); } } newLength = newArray.size(); for(int i=0; i<newArray.size(); i++) { nums[i] = newArray.get(i); } return newLength; }}
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
- 数据库自动备份、自动删除;创建任务本地保存文件
- Human-level concept learning through probabilistic program induction个人理解
- 树套树-区间第k大(带修改)
- gulp自动载入外挂
- Nginx负载均衡(主备)+Keepalived
- 26. Remove Duplicates from Sorted Array
- VS2015编译opencv
- vc 调用CMD执行本地操作
- 树型下拉框组件的构建
- OpenCV笔记1
- Definitely
- solr 基本原理 配置,solr java 初级应用
- 内存泄漏的一些问题
- ScrollView中添加listView