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

边栏推荐
- 直接用的zip包 缺少很多依赖,pip没有,感觉用anaconda create一个环境会方便点
- 默默重新开始,第一页也是新的一页
- 【R语言】把文件夹下的所有文件提取到特定文件夹
- 电学知识的疑问
- After the VB.net program is closed, the background is still connected to SQL
- Output method of list string print(*a) print(““.join(str(c) for c in a) )
- pdf加密、找回密码
- shardingsphere数据分片配置项说明和示例
- Unity C# 委托——事件,Action,Func的作用和区别
- 常用Oracle命令
猜你喜欢

一道很简答但是没答对的SQL题

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

中英文说明书丨TRC 交替醇(Catalogue NumberA575760)

Harbor Enterprise Mirror Warehouse Construction
![[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands](/img/20/a0fb44e9360837146d0ed696c9e992.png)
[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands

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

mongo+ycsb性能测试及线程数分析

idea中PlantUML插件使用

Search 1688 product interface by image (item_search_img-search 1688 product by image (Politao interface) code docking tutorial

力扣刷题180
随机推荐
[R language] Extract all files under a folder to a specific folder
Introduction and use of BeautifulSoup4
pycharm环境包导入到另外一个环境
安装flask
[HNOI2002]营业额统计
APP product source data interface (taobao, jingdong/spelling/suning/trill platform details a lot data analysis interface) code and docking tutorial
普罗米修斯原理及节点发布
Regular Expression - Determine if a string matches the "AABB" pattern
Redis 2 - 高级
CMake中INSTALL_RPATH与BUILD_RPATH问题
IQ Products CMV Brite Turbo试剂盒的原理
Invalid argument(s) appears when redis runs lua script
Import the pycharm environment package into another environment
【R语言】交互作用 测试数据
Adds, deletes, searches, and changes the leading doubly circular linked list (implemented in C language)
详解C语言中的wait()函数和waitpid()函数
DDD 领域驱动设计
Flask failed to create database without error
static静态关键字和继承
.NET高级技术