60. Permutation Sequence
来源:互联网 发布:淘宝联盟互刷 编辑:程序博客网 时间:2024/04/20 07:28
The set [1,2,3,…,n] contains a total of n! unique permutations.
By listing and labeling all of the permutations in order,
We get the following sequence (ie, for n = 3):
“123”
“132”
“213”
“231”
“312”
“321”
Given n and k, return the kth permutation sequence.
Note: Given n will be between 1 and 9 inclusive.
public class Solution { public String getPermutation(int n, int k) { List<Integer> nums = new ArrayList<Integer>(); StringBuilder sb = new StringBuilder(); int fact = 1; for(int i = 1; i <= n; i++){ fact *= i; nums.add(i); } int l = k-1; for(int i = 0; i < n; i++){ fact /= (n-i); int index = l / fact; sb.append(nums.remove(index)); l -= index*fact; } return sb.toString(); }}
0 0
- LeetCode --- 60. Permutation Sequence
- [Leetcode] 60. Permutation Sequence
- [leetcode] 60.Permutation Sequence
- 60. Permutation Sequence
- 60. Permutation Sequence
- **LeetCode 60. Permutation Sequence
- leetcode 60. Permutation Sequence
- 60. Permutation Sequence
- 60. Permutation Sequence
- 60. Permutation Sequence
- 60. Permutation Sequence
- 60. Permutation Sequence
- [LeetCode]60. Permutation Sequence
- LeetCode *** 60. Permutation Sequence
- 60. Permutation Sequence
- LeetCode 60. Permutation Sequence
- hiho 60. Permutation Sequence
- leetcode 60. Permutation Sequence
- ZXing 源码分析(简阅)
- 备忘录
- [POJ2398]Toy Storage(计算几何+二分)
- 查看android studio和apk文件签名
- 输入年月 返回当前月份的天数
- 60. Permutation Sequence
- 前端工程师面试指南
- win10 64位免安装版mysql-5.7.16-winx64安装步骤
- Host 'XXX' is not allowed to connect to this MySQL server 解决方案
- HDU 5739(点双连通)
- UIP协议栈UDP数据发送的问题
- 数据结构课程设计-图书管理开发系统
- 网络程序设计课程学习心得总结
- 联想手机权限开启方法3