当前位置:网站首页>leetcode 之 零移位
leetcode 之 零移位
2022-08-09 06:29:00 【史上最强的弟子】
这道题的关键是对于nums[j] 永远存的是零或者是i == j 的正常整数。
public class Test6 {
public static void main(String[] args) {
Test6 test6 = new Test6();
int[] nums = {0,1,0,3,12};
test6.moveZeroes(nums);
}
public void moveZeroes(int[] nums) {
int j = 0;
for(int i=0;i<nums.length;i++){
if(nums[i]!=0){
nums[j] = nums[i];
if(i != j){
nums[i] = 0;
}
j++;
}
}
System.out.println();
for(int num:nums)
System.out.print(num);
System.out.println();
}
}
输出的结果是:
边栏推荐
- [R language] Extract all files under a folder to a specific folder
- 中英文说明书丨CalBioreagents 山羊抗人白蛋白,IgG组分
- golang zip aes base64
- After the VB.net program is closed, the background is still connected to SQL
- AD的library中 库文件后缀有.intlib .schlib .pcblib 的区别
- 关于如何查找NXP S32K1xx系列单片机的封装信息和引脚定义
- Error: flask: TypeError: 'function' object is not iterable
- 网络学习总结
- 22 high mid term paper topics forecast
- 单例模式
猜你喜欢
Excel受保护的工作表怎么操作?
Fe3O4/SiO2 Composite Magnetic Nanoparticles Aminated on SiO2-NH2/Fe3O4 Surface (Qiyue Reagent)
install flask
MYSQL Advanced Chapter - Query Interception Analysis, Lock Mechanism, Master-Slave Replication
Search 1688 product interface by image (item_search_img-search 1688 product by image (Politao interface) code docking tutorial
DevNet: Deviation Aware Networkfor Lane Detection
中英文说明书丨TRC 交替醇(Catalogue NumberA575760)
GNNExplainer applied to node classification task
ZIP压缩包文件删除密码的方法
sql问题解答创建表的语句
随机推荐
线程的6种状态
idea中PlantUML插件使用
Use of PlantUML plugin in idea
【Feel】Unity Feel插件中,Camera无法正确显示CameraShake
qt send mail program
Use baidu EasyDL intelligent bin
思维方法 解决问题的能力
[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands
中英文说明书丨TRC 交替醇(Catalogue NumberA575760)
CalBioreagents超全Id 蛋白兔单克隆抗体,助力科研
Likou Brush Question 180
.NET高级技术
Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
【Wwise】ArgumentException: The specified path is not of a legal form (empty). About the path reading error in WwiseGlobal
工控设备的系统如何进行加固
Introduction to AIOT
uniapp实现防抖搜索
Unity C# 委托——事件,Action,Func的作用和区别
Used to import the data type
IQ Products巨细胞病毒CMV感染检测试剂盒的特征和应用