当前位置:网站首页>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();
}
}
输出的结果是:
边栏推荐
- Word文件的只读模式没有密码怎么退出?
- 一道很简答但是没答对的SQL题
- Simple Factory Pattern
- 运算放大器(OPA)超详细参数讲解-运放---以及8个型号的运算放大器分析对比
- Simple to use Lambda expressions
- Xilinx Zynq ZynqMP DNA
- 治疗消化性溃疡—Toronto Research Chemicals 甘氨酸铝
- How to find package information and pin definitions for NXP S32K1xx series microcontrollers
- db.sqlite3没有“as Data Source“解决方法
- 深度学习-神经网络原理2
猜你喜欢
随机推荐
Unity Gobang Game Design and Simple AI (2)
C# 利用iTextSharp画PDF
中英文说明书丨TRC 交替醇(Catalogue NumberA575760)
Import the pycharm environment package into another environment
VB.net程序关闭后后台还在与SQL连接
常用Oracle命令
el-table缓存数据
Getting started with kubernetes apparmor
Error jinja2.exceptions.UndefinedError: 'form' is undefined
The solution that does not work and does not take effect after VScode installs ESlint
中英文说明书丨CalBioreagents 醛固酮单克隆抗体
AD的library中 库文件后缀有.intlib .schlib .pcblib 的区别
为什么以太网无法接收大于1500字节的数据包?
Qt 学习(三) —— Qt 模块
数据库中间件-jdbi
Inception V3 闭眼检测
qt send mail program
GNNExplainer应用于节点分类任务
jdepend
深度学习-神经网络原理2