LeetCode刷题(41)--Sort Color
来源:互联网 发布:鹊桥淘宝佣金怎么撤回 编辑:程序博客网 时间:2024/06/15 10:58
1 Pass方案:
把0往前放,把2往后放。
class Solution(object): def sortColors(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. """ p0 = 0 p2 = len(nums) - 1 cur = 0 while cur <= p2: if nums[cur] == 0: nums[cur] = nums[p0] nums[p0] = 0 p0 += 1 elif nums[cur] == 2: nums[cur] = nums[p2] nums[p2] = 2 p2 -= 1 cur -= 1 cur += 1 return
阅读全文
0 0
- LeetCode刷题(41)--Sort Color
- [leetcode] Sort Color
- leetcode color sort
- [leetcode题后感]sort color
- [Leetcode]sort Color
- <LeetCode OJ> 75. Sort Color
- 【leetcode】Array——Sort Color(75)
- LeetCode75(Sort Color)
- Sort Color
- sort color
- Sort Color
- Sort Color
- LeetCode 题解(41): Insertion Sort List
- Sort List leetcode刷题
- [Leetcode刷题]Sort Colors
- Partition Array/ Sort Color
- sort k color
- sort-list(Leetcode)
- 插入排序 心得
- 【工作中学到的小技巧】在/etc/profile中添加path后导致linux命令都不能用
- PHP设计模式系列
- 三种均衡器的MATLAB实现
- dbforget mysql connection 20171118
- LeetCode刷题(41)--Sort Color
- 接口数据改变对应的PullToRefresh展示效果也改变
- java.io.IOException: response already committed
- 简单实现 二级列表购物车(固定数据)
- The Definitive Guide to Squarespace.pdf 英文原版 免费下载
- VC 调用GDI+绘图
- 【Ubuntu】Ubuntu16.04安装WPS及解决字体缺失问题
- 雅可比迭代法
- Centos6.5使用NAT方式配置网络