python写算法题:leetcode: 31. Next Permutation
来源:互联网 发布:平面画图软件 编辑:程序博客网 时间:2024/06/10 02:49
https://leetcode.com/problems/next-permutation/#/description
class Solution(object): def nextPermutation(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. """ if len(nums)<=1: return raisepos=0 for vpos in xrange(1,len(nums)): if nums[vpos-1]<nums[vpos]: raisepos=vpos if raisepos == 0: nums.sort() else: minv=nums[raisepos-1] reppos=raisepos for repind in xrange(raisepos+1, len(nums)): if nums[repind]>minv and nums[repind]<nums[reppos]: reppos=repind tmp=nums[reppos] nums[reppos]=minv nums[raisepos-1]=tmp nums[raisepos:]=sorted(nums[raisepos:])
阅读全文
0 0
- python写算法题:leetcode: 31. Next Permutation
- 31. Next Permutation Leetcode Python
- [leetcode: Python]31.Next Permutation
- 【Leetcode】【python】Next Permutation
- LeetCode算法题之Next Permutation
- LeetCode算法题——Next Permutation
- [LeetCode]31.Next Permutation
- LeetCode --- 31. Next Permutation
- [Leetcode] 31. Next Permutation
- LeetCode 31.Next Permutation
- [leetcode] 31.Next Permutation
- [leetcode] 31. Next Permutation
- *LeetCode 31. Next Permutation
- Leetcode 31. Next Permutation
- leetcode 31. Next Permutation
- 31. Next Permutation LeetCode
- leetcode 31. Next Permutation
- leetcode 31. Next Permutation
- tiny6410的IIC裸机驱动
- [题解]codeforces 339d Xenia and Bit Operations
- 【Linux API】Sysfs & sysfs_notify文件系统
- 图象直方图的线性变换——直方图拉伸
- 玩转h5之layaide设计fd编程
- python写算法题:leetcode: 31. Next Permutation
- win10+mysql
- 对象模型图(OMD)
- java NIO基本操作
- 常用的hash算法
- 在Ubuntu14.04下编译程序出现缺失libudev.h
- OpenGL入门(二)
- fgm实例练习笔记-3.8简易网页时钟
- Android Service完全解析,关于服务你所需知道的一切(上)