当前位置:网站首页>LeetCode每日两题01:删除排序数组中的重复项 (均1200道)
LeetCode每日两题01:删除排序数组中的重复项 (均1200道)
2022-08-07 15:13:00 【那人独钓寒江雪.】

解题思路:因为数组是排序的,只要是相同的肯定是挨着的,我们只需要遍历所有数组,然后前后两两比较,如果有相同的就把后面的给删除。
上一位和下一位两两比较 下一位和下下一位两两比较
class Solution {
public int removeDuplicates(int[] nums) {
int i=0;
for (int j=1;j<nums.length;j++){
if (nums[i]!=nums[j]){
i+=1;
nums[i]=nums[j];//去除重复项的关键
}
}
return i+1;
}
}
边栏推荐
- 微信小程序——小程序中计算属性的使用
- 联盛德W801系列4-MQTT使用
- [HCIP] Small Experiment on BGP Routing Problem
- LeetCode HOT HOT 100 (9. Telephone number letter combinations)
- WeChat automatic card issuance robot description
- RTT学习笔记10- 设备IPC 完成量-ringbufffer-workwueue
- Open3D ICP精配准(点到面)
- C Expert Programming Chapter 8 Why Programmers Can't Tell the Difference Between Halloween and Christmas 8.7 Implementing Finite State Machines in C
- 【Electrical Engineering (Part 2)】Organization of some basic concepts
- AdaptFormer学习笔记
猜你喜欢

俩日总结(【20】【21】)

RTT学习笔记10- 设备IPC 完成量-ringbufffer-workwueue

WeChat automatic card issuance robot description

Lianshengde W801 series 4-MQTT use

分库分表和分布式acp和分布式事务

【通信原理】第四章 -- 信道

RTT学习笔记7-中断管理

C专家编程 第7章 对内存的思考 7.8 轻松一下---“Thing King”和“页面游戏”

LeetCode高频题:dfs排列组合问题,剪枝策略,参观展厅总时间120分钟,请你给出所有可能的参观方案的个数

联盛德W801系列4-MQTT使用
随机推荐
服务器管理面板aaPanel使用中的一些问题汇总
【PTA】L2-033 Simple Calculator (25 points)
Flink CDC
RTT学习笔记11- gpio使用和GPIO设备驱动框架层
IPV6的内容
LeetCode HOT HOT 100 (9. Telephone number letter combinations)
Chapter 8 C programming expert why programmers cannot distinguish where Halloween and Christmas 8.5 prototype fail
LeetCode高频题:dfs排列组合问题,剪枝策略,参观展厅总时间120分钟,请你给出所有可能的参观方案的个数
微信小程序——video视频全屏展示
RTT学习笔记12-串口外设和串口驱动框架
响应状态码
Lianshengde W801 series 1-flash save data routine: save wifi distribution network information
微信小程序——image图片自适应
【Verilog】组合逻辑电路 -- 程序设计及应用
微信小程序——小程序去除文本中的<br>标签
C专家编程 第8章 为什么程序员无法分清万圣节和圣诞节 8.7 用C语言实现有限状态机
win10 uwp 分治法
二、工业方案推荐系统
n个骰子的点数------2022/08/04
Niu Ke Interview High Frequency List (Group 2) Difficulty: Easy & Moderate