Leetcode 283 Move Zeroes
2016-05-17 14:23
323 查看
Given an array
For example, given
Note:
You must do this in-place without making a copy of the array.
Minimize the total number of operations.
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,
numsshould be
[1, 3, 12, 0, 0].
Note:
You must do this in-place without making a copy of the array.
Minimize the total number of operations.
class Solution(object): def moveZeroes(self, nums): c = 0 for i in range(len(nums)): if nums[i] != 0: nums[c] = nums[i] c += 1 for i in range(c,len(nums)): nums[i] = 0
相关文章推荐
- ROS中service 与action 的区别
- wireshark
- 数组------荷兰国旗问题(颜色排序)
- Mysql多实例安装
- 架构漫谈(一):什么是架构?
- 分词词云 logistic相关研究 2016.05.16回顾
- Settings.apk修改
- HDU 2665 Kth number 划分树
- UISegmentedControl的用法
- part1:15-安装Linux系统到开发板
- iOS 计时器 单例 GCD 切换控制器倒计时继续读秒
- ansible playbook 学习
- java基础第八天_多线程
- Netty 实现聊天功能
- 【Android】关于addTextChangedListener()方法的上机记录
- 杭电1495
- 简单的tcp服务
- org.apache.commons.lang3.ArrayUtils 学习笔记
- memcached添加IP白名单,只允许指定服务器调用
- 便携名片app