当前位置:网站首页>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] interaction test data
- io.lettuce.core.RedisCommandTimeoutException Command timed out
- 2022-08-08: Given an array arr, it represents the height of the missiles that will appear in order from morning to night.When the cannon shoots missiles, once the cannon is set to shoot at a certain h
- workbench 数据导出
- el-table缓存数据
- PDF不能打印和复制的问题如何解决?
- 抗菌药物丨Toronto Research Chemicals 天冬酰胺D
- IQ Products CMV Brite Turbo试剂盒的原理
- XxlJobConfig分布式定时器任务管理XxlJob配置类,替代
- crc calculation
猜你喜欢
![[GO]、数组与切片](/img/71/86126c41d0f43aa8b9f232b219f5d7.png)
[GO]、数组与切片

MYSQL Advanced Chapter - Query Interception Analysis, Lock Mechanism, Master-Slave Replication

代码目录结构

sql问题解答创建表的语句

Harbor Enterprise Mirror Warehouse Construction

关于如何查找NXP S32K1xx系列单片机的封装信息和引脚定义

报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS重大开销和将disab补充道

工控设备的系统如何进行加固

Gao Zelong, a famous digital collection expert and founder of the Digital Collection Conference, was interviewed by China Entrepreneur Magazine

Unity 五子棋游戏设计和简单AI(2)
随机推荐
简单使用Lambda表达式
Fragments
Unity 五子棋游戏设计和简单AI(2)
中英文说明书丨TRC 交替醇(Catalogue NumberA575760)
Web APIs BOM- 操作浏览器:本地存储
[GO]、数组与切片
static静态关键字和继承
【R语言】把文件夹下的所有文件提取到特定文件夹
Use of PlantUML plugin in idea
变压器的工作原理(图解,原理图讲解,一看就懂)
db.sqlite3没有“as Data Source“解决方法
IQ Products巨细胞病毒CMV感染检测试剂盒的特征和应用
[MySQL]二、进程的关系、MySQL密码破解、建表和建库相关命令
INSTALL_RPATH and BUILD_RPATH problem in CMake
untiy countdown
tidb crash test
【R语言】交互作用 测试数据
代码目录结构
crc calculation
Harbor Enterprise Mirror Warehouse Construction