[leetcode]--26. Remove Duplicates from Sorted Array
来源:互联网 发布:java 工具类打包jar包 编辑:程序博客网 时间:2024/06/07 05:51
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 i = 0; for (int j = 1; j < nums.length; j++) { if (nums[j] != nums[i]) { i++; nums[i] = nums[j]; } } return i + 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
- 26. Remove Duplicates from Sorted Array LeetCode
- 【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
- 26.[Leetcode]Remove Duplicates from Sorted Array
- Javascript—switch语句
- Java八大排序算法之直接插入排序
- gif动图录制软件
- 自定义注解
- 设计模式学习笔记(抽象工厂模式)
- [leetcode]--26. Remove Duplicates from Sorted Array
- Spring中IoC的入门实例
- 最小K数之和
- 二十三种设计模式之访问者模式
- 3.1.3 WebView 文件下载、缓存、内存泄露
- sqlmap做sql注入测试
- 【ZZULIOJ】 2181 GJJ的日常之暴富梦
- NYOJ20
- java文件上传