终于碰到一道水题,睡觉去~

Move Zeroes

Total Accepted: 37369 Total Submissions: 88383 Difficulty: Easy

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.

For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0].

Note:

  1. You must do this in-place without making a copy of the array.
  2. Minimize the total number of operations.

还有一点,我写代码的时候,用C和C++竟然很不熟悉,不如用Java方便。这说明急需复习!

Java:

 public class Solution {
public void moveZeroes(int[] nums) {
for (int i = 0; i < nums.length; i++) {
if (nums[i] == 0) {
for (int j = i + 1; j < nums.length; j++) {
if(nums[j] != 0) {
nums[i] = nums[j];
nums[j] = 0; break;
}
}
}
} }
}

最新文章

  1. NFS Volume Provider(Part II) - 每天5分钟玩转 OpenStack(63)
  2. thinkPHP-空操作
  3. Android常见控件— — —Button
  4. zk框架中利用map类型传值来创建window,并且传值
  5. Android 长按Listview显示CheckBox,实现批量删除。
  6. angular-file-upload 中文API
  7. VGG_19 train_vali.prototxt file
  8. MySQL快速生产表的描述
  9. Struts2配置细节
  10. JS相关链接
  11. 解决mongodb设备mongod命令不是内部或外部的命令
  12. Andy的生活
  13. GP项目总结(一)
  14. Caffe Ubuntu16.04 GPU安装
  15. Junit Framework -TestRule,自动化测试中如何再次运行失败的测试用例
  16. Kubernetes资源监控探索
  17. Vector HashMap List 存取数据速度
  18. Python面向对象(类的成员之方法)
  19. JS事件细分
  20. javascript和python取dict字典对象的不同

热门文章

  1. VS2010+VMWare8+VisualDDK1.5.6 创建并调试你的第一个驱动程序 - 完全教程
  2. 执行powershell脚本
  3. 通过AngularJS实现图片上传及缩略图展示
  4. 【MySQL】MySQL 5.7+ 版本的初始化
  5. EMR,电子病历(Electronic Medical Record)
  6. JS 之作用域链和闭包
  7. WebForm---增删改(内置对象)
  8. newCachedThreadPool线程池
  9. ORA-01704: string literal too long
  10. servlet3.0,web.xml的metadata-complete的作用