60. Permutation Sequence
来源:互联网 发布:bind 域名冲突 编辑:程序博客网 时间:2024/05/01 18:18
//开始还考虑当这个n特别大,导致n!>int_max,然而k<int_max怎么办,后来发现题设没考虑这些边界条件,那就无所谓啦,直接解出来class Solution {public: void get_kth(string &s,int factorial,int k,bool * flag,int n) { if(n==s.size()) return; int m=(k-1)/factorial+1; k-=(m-1)*factorial; for(int i=0;i<m;i++) { if(flag[i]) m++; } flag[m-1]=true; s.push_back(m+'0'); if(n!=s.size()) factorial/=(n-s.size()); get_kth(s,factorial,k,flag,n); } string getPermutation(int n, int k) { int factorial=1; for(int i=1;i<n;i++) factorial*=i;//(n-1)! string s; bool * flag=new bool[n]; memset(flag,false,sizeof(bool)*n); get_kth(s,factorial,k,flag,n); return s; }};
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
- 终生受益的职业规划(转自惠普前总裁)
- 【Machine Learning实验5】SVM实验
- Ant_的最完整build.xml解释
- [LeetCode]Missing Number
- java13天
- 60. Permutation Sequence
- Machine Learning实验6 理解核函数
- ECHI和OCHI
- Unity3D学习1——鼠标点击效果显示
- 双击文件夹新建一个窗口问题
- 来CSDN写博客的一些原因
- VS2012 的插件安装后,出现的ActivityLog.xml 日记错误的解决方案
- machine learning实验7 矩阵求逆
- ViewTreeObserver实现自动更新