leetcode31 Next Permutation
来源:互联网 发布:淘宝排名在线查询 编辑:程序博客网 时间:2024/05/29 18:52
解题思路:从后向前搜索,找到第一个按升序的元素对,然后再从后向前搜索,找到元素对之后第一个大于较小元素的元素,将他们交换,然后反转交换前较小元素之后的元素
class Solution(object): def Next_Permutation(self,nums): partition=-1 for i in range(len(nums)-2,-1,-1): if num[i]<num[i+1] partition=i break if partition==-1: nums.reverse() else: for i in range(len(nums)-1,partition,-1): if num[i]>num[partition]: num[i],num[partition]=num[partition],num[i] break nums[partition+1:]=nums[partition+1:][::-1]
阅读全文
0 0
- [LeetCode31]Next Permutation
- LeetCode31:Next Permutation
- Leetcode31 Next Permutation
- LeetCode31 Next Permutation
- leetcode31:Next Permutation
- leetcode31---Next Permutation
- Leetcode31 Next Permutation
- LeetCode31. Next Permutation
- leetcode31. Next Permutation
- leetcode31~Next Permutation
- LeetCode31. Next Permutation
- Leetcode31. Next Permutation
- leetcode31. Next Permutation
- LeetCode31. Next Permutation
- leetcode31 Next Permutation
- Leetcode31 Next Permutation
- leetcode31. Next Permutation
- LeetCode31. Next Permutation最清晰的解法
- 仿CNode.js论坛学习
- jeecg 3表联查
- Java的运行时数据区
- SSH入门项目-1-环境准备
- SVM与Logistic回归的关系
- leetcode31 Next Permutation
- Android 8.0 功能和 API
- SSH连接远程服务器
- 2017-9-15河南财经政法大学开学典礼校长致辞-向阳而立,向善而行
- 正则表达式 Regex
- 使用Spring单元测试出错
- win10 uwp MVVM 轻量框架
- 银行存钱系统可行性分析
- 使用Web Speech API实现语音文本互转