leetcode31_Next Permutation
来源:互联网 发布:linux中80端口被占用 编辑:程序博客网 时间:2024/05/29 19:37
这道题的题目含义是:给你一串数字{1,2,4,4,6},这串数字按从前往后组的成一个数就是:12446,(假设这几个数排列组合得到的一个集合为X),要求你用这几个数字得到一个新的数字,这个新的数字要比1244大,并且是X中所有比12446大的最小数,即:14246成立。如果没找到比它大的,则输出能得到最小数的一个组合。
求解思路:因为要找下一个比它大的最小数字,倒序遍历数组,设置两个指针n1,n2(n2在后面靠近尾部),如果n2指的数字大于n1指的数字,那么找到从n2到末尾中比n1大的最小数字(可以用二分法,因为n2到末尾的数字一定是从大到小排好的),则交换这两个数字,然后把从n2到末尾的数字按从小到大排列如果n1都已经到头部了都还没有n2 > n1的数字,说明这串数字本身就是从大到小排列的,已经是最大了,那么,从尾部输出到头部输出这串数字即可。
阅读全文
0 0
- leetcode31_Next Permutation
- Permutation
- Permutation
- permutation
- Permutation
- Permutation
- Permutation
- permutation
- Permutation
- permutation
- Permutation
- Permutation
- permutation
- permutation
- permutation
- Permutation, next Permutation, Permutation sequence
- Complete Permutation
- 排列(Permutation)
- /usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid sym
- Tomcat中设置http跳https
- 设计模式-创建模式之Factory Method
- 仿射变换
- 纯css绘制三角形
- leetcode31_Next Permutation
- Android中跨进程通信的方式
- jdk1.8特性
- linux kjournald 进程IO高的处理办法
- Mac下ImportError: No module named content/ModuleNotFoundError: No module named 'itchat.content';
- 一组数字去重
- Jquery组件封装之鼠标移入移出图片透明度变化
- 使php的编码与java的编码保持一致
- 天池—广东政务数据创新大赛—智能算法赛总结