当前位置:网站首页>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();
}
}
输出的结果是:

边栏推荐
- String.toLowerCase(Locale.ROOT)
- Flask failed to create database without error
- 中英文说明书丨TRC D-阿卓糖(D-Altrose)
- 变压器的工作原理(图解,原理图讲解,一看就懂)
- Ferric oxide/bismuth sulfide nanocomposites ([email protected]@BSABiS nanoparticles) | dendrimer-stabilized bismuth sulfide nanop
- Reverse Engineering
- Unity五子棋游戏设计 和简单AI实现(1)
- 抗菌药物丨Toronto Research Chemicals 天冬酰胺D
- Fe3O4/SiO2 Composite Magnetic Nanoparticles Aminated on SiO2-NH2/Fe3O4 Surface (Qiyue Reagent)
- kubernetes security
猜你喜欢

The solution that does not work and does not take effect after VScode installs ESlint

Unity Gobang Game Design and Simple AI (2)

力扣刷题180

C language implements sequential stack and chain queue

PDF不能打印和复制的问题如何解决?

Use baidu EasyDL intelligent bin

Magnetic Core-Shell Fe3O4 Particles Supported Gold Nanostars | Magnetic Fe3O4-POSS-COOH | Superparamagnetic Fe3O4-Polydopamine Core-Shell Nanoparticles

redis 运行lua 脚本 出现Invalid argument(s)

Cysteine/Galactose/Perylenediimide Functionalized Fe3O4 Fe3O4 Nanomaterials | Scientific Research Reagents

Search 1688 product interface by image (item_search_img-search 1688 product by image (Politao interface) code docking tutorial
随机推荐
思维方法 解决问题的能力
中英文说明书丨CalBioreagents 醛固酮单克隆抗体
IQ Products CMV Brite Turbo试剂盒的原理
Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
BeautifulSoup4的介绍与使用
代码目录结构
Unity Gobang Game Design and Simple AI(3)
Inception V3 闭眼检测
语句加锁分析
【Feel】Unity Feel插件中,Camera无法正确显示CameraShake
untiy countdown
Web APIs BOM- 操作浏览器:本地存储
运算放大器(OPA)超详细参数讲解-运放---以及8个型号的运算放大器分析对比
uniapp实现防抖搜索
05 多线程与高并发 - ThreadPoolExecutor 源码解析
[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands
Unity 五子棋游戏设计和简单AI(3)
APP product source data interface (taobao, jingdong/spelling/suning/trill platform details a lot data analysis interface) code and docking tutorial
数据库中间件-jdbi
.NET高级技术