当前位置:网站首页>Force buckle deletes duplicates in the sort array
Force buckle deletes duplicates in the sort array
2022-06-24 01:10:00 【Love each other when flowers fall】
Here's an ordered array nums , Would you please In situ Delete duplicate elements , Make each element Only once , Returns the new length of the deleted array .
Don't use extra array space , You must be there. In situ Modify input array And using O(1) Complete with extra space .
Example 1: Input :nums = [1,1,2] Output :2, nums = [1,2] explain : Function should return the new length 2 , And the original array nums The first two elements of are modified to 1, 2 . You don't need to think about the elements in the array that follow the new length . Example 2: Input :nums = [0,0,1,1,1,2,2,3,3,4] Output :5, nums = [0,1,2,3,4] explain : Function should return the new length 5 , And the original array nums The first five elements of are modified to 0, 1, 2, 3, 4 . You don't need to think about the elements in the array that follow the new length . Tips : 0 <= nums.length <= 3 * 104 -104 <= nums[i] <= 104 nums In ascending order
class Solution {<!-- -->
public int removeDuplicates(int[] nums) {<!-- -->
// Special case handling
if(nums==null||nums.length==0){<!-- -->
return 0;
}
int left = 0,right = 0;
while (right<nums.length){<!-- -->
if(nums[left]!=nums[right]) {<!-- -->
nums[++left] = nums[right];
}
right++;
}
return left+1;
}
}边栏推荐
- C language: recursively implementing factorial of n
- Cvpr2022 𞓜 thin domain adaptation
- Pad User Guide
- 智能制造时代下,MES管理系统需要解决哪些问题
- 【小程序】实现双列商品效果
- How to view kubernetes API traffic by grabbing packets
- Sockfwd a data forwarding gadget
- 数据管理:业务数据清洗,落地实现方案
- Cross domain and jsonp
- Skywalking installation and deployment practice
猜你喜欢

What problems need to be solved by MES management system in the era of intelligent manufacturing

【小程序】实现双列商品效果

机器学习中 TP FP TN FN的概念

LSF opens job idle information to view the CPU time/elapse time usage of the job

Perhaps the greatest romance of programmers is to commemorate their dead mother with a software

Installation and use of winscp and putty

13 `bs_duixiang.tag标签`得到一个tag对象

GNN upper edge distributor! Instead of trying to refine pills, you might as well give your GNN some tricks

Niu Xuechang's anniversary celebration: software promotion, limited time and free registration code!

一次 MySQL 误操作导致的事故,「高可用」都顶不住了!
随机推荐
2021-11-21: map[i][j] = = 0, which means that (I, J) is an ocean. If you cross it, the cost will be
Map data types in golang
智能制造时代下,MES管理系统需要解决哪些问题
Gin framework: automatically add requestid
[iccv workshop 2021] small target detection based on density map: coarse-grained density map guided object detection in aerial images
If you want to open an account for stock trading, is it safe to open an account online-
现在网上开股票账户安全吗?选择国有券商,最快8分钟开户成功
解决base64压缩文件,经过post请求解压出来是空格的问题
【CVPR 2020 Oral】极低光去噪论文:A Physics-based Noise Formation Model for Extreme Low-light Raw Denoising
ARM学习(7) symbol 符号表以及调试
Data management: business data cleaning and implementation scheme
Application configuration management, basic principle analysis
应用配置管理,基础原理分析
Shengdun technology joined dragon lizard community to build a new open source ecosystem
Experience summary of 9 Android interviews, bytes received, Ali, advanced Android interview answer
numpy. linalg. Lstsq (a, B, rcond=-1) parsing
一次 MySQL 误操作导致的事故,「高可用」都顶不住了!
Real time computing framework: Spark cluster setup and introduction case
牛学长周年庆活动:软件大促限时抢,注册码免费送!
【机器学习】线性回归预测