hiho 60. Permutation Sequence
来源:互联网 发布:盐城大数据产业园 编辑:程序博客网 时间:2024/05/01 20:05
问题
https://leetcode.com/problems/permutation-sequence/
解法
复杂度o(n^2)
class Solution {public: string getPermutation(int n, int k) { bool flag[n+1]; int f = 1; for (int i=1; i<=n; ++i) { f*= i; flag[i] = true; } string ret(n, '0'); for (int i=0; i<n; ++i) { f /= (n-i); int reverse = n- i -1; int v; for (int j=reverse; j>=0; --j) if (j*f < k)// 第j大数 前面有j *((now-1)!) 个数, 找到最大的j { v = j; break; } k-= v*f; int s = -1; for (int j=1; j<= n; ++j)//找第v大数。 if (flag[j]) { ++s; if (s== v) { ret[i] += j; flag[j] = false; break; } } } return ret; }};
0 0
- hiho 60. Permutation Sequence
- 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
- leetcode 60. Permutation Sequence
- “UITableView完美平滑滚动”阅读笔记
- Matlab多线程与多核运算, 以及GPU加速
- Git学习8:Git分支操作
- 所有编程皆为Web编程
- 正则表示式实例1--判断某个数是不是4的幂数
- hiho 60. Permutation Sequence
- AndroidStudio简单快速导入GitHub中的第三方插件
- 成为优秀程序员的方法就是抛开编程?
- ServiceManager如何成为Binder进程通信的守护进程
- 培训有用吗?软件行业应采用“学徒制”
- 51nod 1126(矩阵快速幂)
- poj 2752 Seek the Name, Seek the Fame
- Xshell使用
- Linux上连接sybase数据库