next-permutation
来源:互联网 发布:淘宝rol是什么意思 编辑:程序博客网 时间:2024/06/05 17:54
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).
The replacement must be in-place, do not allocate extra memory.
Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column.
1,2,3→1,3,2
3,2,1→1,2,3
1,1,5→1,5,1
import java.util.*;public class Solution { public void nextPermutation(int[] num) { if(num==null||num.length<=0){ return; } for(int i=num.length-1;i>0;i--){ if(num[i]>num[i-1]){ for(int j=num.length-1;j>i-1;j--){ if(num[i-1]<num[j]){ int tmp=num[i-1]; num[i-1]=num[j]; num[j]=tmp; Arrays.sort(num,i,num.length); return; } } } } Arrays.sort(num,0,num.length); }}参考http://blog.csdn.net/qq575787460/article/details/41215475
阅读全文
0 0
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Next Permutation
- Python没有运行快捷按钮
- Android DecorView浅析
- android 系统数据业务---打开
- mysql的两种安装方式
- Android APK 上架
- next-permutation
- python常用模块与socket编程
- HTML5
- G
- React之PropTypes属性
- 水平居中和transform: translateY(-50%) 实现元素垂直居中效果
- 第一个django小测试
- 2017年7月做好SEO优化的30点建议
- javaEE的开发模式