**LeetCode 60. Permutation Sequence
来源:互联网 发布:淘宝搜索的算法 编辑:程序博客网 时间:2024/05/01 08:59
https://leetcode.com/problems/permutation-sequence/
康拓展开和逆康拓展开
自己推一推 参考http://www.cnblogs.com/hxsyl/archive/2012/04/11/2443009.html
class Solution {public: string getPermutation(int n, int k) { k--; for(int i=0;i<=n;i++){ vis[i]=0; if(i == 0)jie[i]=1; else jie[i] = (i)*jie[i-1]; } string ret; for(int i=n-1;i>0;i--) { int div = k/jie[i]; int mod = k%jie[i]; ret = ret + getDiv(div+1,n); //cout << "div=" << div << " " << " mod=" << mod << endl; k = mod; } for(int i=1;i<=n;i++) if(!vis[i]) ret = ret + (char)(i+'0'); return ret; } char getDiv(int d, int n) { int cnt=0; for(int i=1;i<=n;i++) { if(!vis[i]) { cnt++; if( cnt == d ) { vis[i] = 1; return (char)(i+'0'); } } } return '0'; }private: int vis[10], jie[10];};
0 0
- LeetCode --- 60. Permutation Sequence
- [Leetcode] 60. Permutation Sequence
- [leetcode] 60.Permutation Sequence
- **LeetCode 60. Permutation Sequence
- leetcode 60. Permutation Sequence
- [LeetCode]60. Permutation Sequence
- LeetCode *** 60. Permutation Sequence
- LeetCode 60. Permutation Sequence
- leetcode 60. Permutation Sequence
- LeetCode 60. Permutation Sequence
- leetcode:60. Permutation Sequence
- [Leetcode] 60. Permutation Sequence
- [leetcode] 60. Permutation Sequence
- [LeetCode] 60. Permutation Sequence
- leetcode 60. Permutation Sequence
- Leetcode-60. Permutation Sequence
- [LeetCode]--60. Permutation Sequence
- leetcode-60. Permutation Sequence
- UNIX的各种文字游戏
- <LeetCode><Easy> 328. Odd Even Linked List
- POJ 1077 Eight(八数码第八境界|IDA*+曼哈顿距离+判断是否有解)
- 八数码的几种做法的总结以及是否有解的判断
- leetCode 226. Invert Binary Tree
- **LeetCode 60. Permutation Sequence
- (一二二)运算符重载——第十一章
- Android Studio——SAX解析XML
- (一二二)友元函数
- Learning how to learn(1)
- Linux(Ubuntu, Fedora, Vmware)使用笔记(1)
- Final Keyword In Java
- (一二三)矢量坐标计算
- (一二四)给类对象赋值、以及类对象的返回值