当前位置:网站首页>LeetCode Daily 2 Questions 01: Delete Duplicates in Sorted Arrays (both 1200 questions)
LeetCode Daily 2 Questions 01: Delete Duplicates in Sorted Arrays (both 1200 questions)
2022-08-07 15:37:00 【The man fishing alone like snow.】

Problem-solving idea: Because the arrays are sorted, as long as they are the same, they must be next to each other. We only need to traverse all the arrays, and then compare them in pairs, and delete the latter if they are the same.
Pairwise comparison of the previous and next bits Comparison of the next and next bits in pairs
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];//removeKey to Duplicates}}return i+1;}}边栏推荐
猜你喜欢
随机推荐
Understanding of bubble sort
jmter正则表达式提取器
【Verilog】组合逻辑电路 -- 程序设计及应用
C Expert Programming Chapter 7 Thinking About Memory 7.8 Take it easy --- "Thing King" and "Page Game"
Pytorch介绍以及基本使用
LeetCode 热题 HOT 100(7.盛最多水的容器)
LeetCode 热题 HOT 100(8.三数之和)
Open3D 点云变换(变换矩阵)
LeetCode 热题 HOT 100(6.正则表达式匹配)
JWT的创建
小技巧——postman生成在线文档
Programming Experts in C Chapter 8 Why Programmers Can't Tell the Difference Between Halloween and Christmas 8.1 The Portzebie Weights and Measures System
LeetCode每日两题02:买股票的最佳时机 (均1200道)
小技巧——postman配置token
LeetCode 热题 HOT 100(5.最长回文子串)
05 【接口 interface VS type】
shell脚本入门学习
微信小程序——小程序去除文本中的<br>标签
RTT学习笔记11- gpio使用和GPIO设备驱动框架层
AQS synchronization component - Semaphore (semaphore) analysis and case









