LeetCode 26. Remove Duplicates from Sorted Array 题解——Java
来源:互联网 发布:林立雯的淘宝店 编辑:程序博客网 时间:2024/06/06 05:37
题目链接:https://leetcode.com/problems/remove-duplicates-from-sorted-array/#/description
题目要求:对于一个已排好序的数组,返回去掉其中的重复元素之后的数组长度。
思路:使用一个指针指示下一个不同的元素应该处于的正确位置。
Java代码如下:
public class Solution { public int removeDuplicates(int[] nums) { int rightIndex = 1; for(int i=1; i<nums.length; i++){ if(nums[i] != nums[i-1]){ nums[rightIndex] = nums[i]; rightIndex++; } } return rightIndex; }}
0 0
- LeetCode 26. Remove Duplicates from Sorted Array 题解——Java
- LeetCode题解——Remove Duplicates from Sorted Array
- leetcode——26. Remove Duplicates from Sorted Array && 80. Remove Duplicates from Sorted Array II
- LeetCode题解:Remove Duplicates from Sorted Array
- [LeetCode]Remove Duplicates from Sorted Array题解
- Remove Duplicates from Sorted Array---leetcode 我的java题解
- LeetCode—Remove Duplicates from Sorted Array
- Leetcode题解14 26. Remove Duplicates from Sorted Array
- LeetCode 26 — Remove Duplicates from Sorted Array(Java)
- Leetcode——26. Remove Duplicates from Sorted Array
- [Leetcode] Remove Duplicates from Sorted Array (Java)
- [LeetCode][Java] Remove Duplicates from Sorted Array
- 【leetcode】Remove Duplicates from Sorted Array【java】
- leetcode:Remove Duplicates from Sorted Array 【Java】
- LeetCode : Remove Duplicates from Sorted Array [java]
- [LeetCode]26.Remove Duplicates from Sorted Array
- LeetCode 26. Remove Duplicates from Sorted Array
- LeetCode --- 26. Remove Duplicates from Sorted Array
- OpenCV目标跟踪-LK光流法
- 一.memcached简介and安装
- MySql知识点索引_01
- uboot2013或新版uboot启动内核失败问题的解决
- epoll实例(Linux)
- LeetCode 26. Remove Duplicates from Sorted Array 题解——Java
- Visual Studio Code C&&C++ 编译配置
- 对交换机与路由器的认知
- 【HDUoj】5969
- 《深入理解 Java 虚拟机》- 笔记
- Lisp em
- html中使用frameset布局
- CSRF学习笔记之CSRF的攻击与防御以及审计【00x1 】
- Python排序——直接插入排序