当前位置:网站首页>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();
}
}
输出的结果是:
边栏推荐
- TCP segment of a reassembled PDU
- Word文件的只读模式没有密码怎么退出?
- Redis 2 - 高级
- After the VB.net program is closed, the background is still connected to SQL
- 按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
- Flask failed to create database without error
- 中英文说明书丨TRC D-阿卓糖(D-Altrose)
- 单例模式
- Unity Gobang Game Design and Simple AI(3)
- Ferric oxide/bismuth sulfide nanocomposites ([email protected]@BSABiS nanoparticles) | dendrimer-stabilized bismuth sulfide nanop
猜你喜欢
锁执行的过程
Adds, deletes, searches, and changes the leading doubly circular linked list (implemented in C language)
Word文件的只读模式没有密码怎么退出?
Deep Learning - Principles of Neural Networks 2
redis 运行lua 脚本 出现Invalid argument(s)
Getting started with kubernetes apparmor
Unity五子棋游戏设计 和简单AI实现(1)
DevNet: Deviation Aware Networkfor Lane Detection
[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands
一道很简答但是没答对的SQL题
随机推荐
AD的library中 库文件后缀有.intlib .schlib .pcblib 的区别
[R language] Extract all files under a folder to a specific folder
Redis 2 - 高级
Altium designer软件常用最全封装库,包含原理图库、PCB库和3D模型库
05 多线程与高并发 - ThreadPoolExecutor 源码解析
Introduction of convenient functions and convenient shortcut keys of vs tomato assistant
什么是excel文件保护
为什么以太网无法接收大于1500字节的数据包?
phpstudy install flarum forum
按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
Simple Factory Pattern
Invalid argument(s) appears when redis runs lua script
A test engineer with an annual salary of 35W was laid off. Personal experience: advice that you have to listen to
Word文件的只读模式没有密码怎么退出?
【R语言】对文件进行归一化整理到各文件类型文件夹
线程的6种状态
VS2019 common shortcut keys
VS2019常用快捷键
程序性能分析 —— 复杂度分析
Unity C# 委托——事件,Action,Func的作用和区别