LintCode:数组划分
2016-04-26 23:39
253 查看
LintCode:数组划分
一前一后两根指针,当前面的指针大于k且后指针小于k时,交换两个指针的值,走到两根指针相遇。
一前一后两根指针,当前面的指针大于k且后指针小于k时,交换两个指针的值,走到两根指针相遇。
class Solution: """ @param nums: The integer array you should partition @param k: As description @return: The index after partition """ def partitionArray(self, nums, k): # write your code here # you should partition the nums by k # and return the partition index as description m = 0 n = len(nums) - 1 while(m < n): while nums[m] < k and m < n: m += 1 while nums >= k and m < n: n -= 1 nums[m], nums = nums , nums[m] m = m + 1 n = n - 1 for i in range(len(nums)): if nums[i] >= k: return i return len(nums)
相关文章推荐
- string 字符串常量
- leetcode 111.Minimum Depth of Binary Tree-树最小深度|深度遍历|广度遍历
- Vijos1776关押罪犯
- 最长回文子串-Manacer算法
- JAVA每日总结
- JVM 类型的生命周期学习
- Redis的AOF持久化-Redis学习笔记四
- sass、less和stylus的安装使用和入门实践
- c++上机报告4
- Java 接口和抽象类区别
- linux修改用户目录文件名
- Mysql5.6配置文件详解
- 贪心算法经典例子
- Atitit.增强系统稳定性----虚拟内存的设置
- 工具函数(二)
- Atitit.增强系统稳定性----虚拟内存的设置
- c++ 11(四)
- 为什么跑步比赛是逆时针跑?
- C++实验4-穷举法解决组合问题
- c++课后作业4