Leetcode 60. Permutation Sequence (Medium) (cpp)
来源:互联网 发布:80端口被屏蔽 编辑:程序博客网 时间:2024/06/15 23:06
Leetcode 60. Permutation Sequence (Medium) (cpp)
Tag: Backtracking, Math
Difficulty: Medium
/*60. Permutation Sequence (Medium)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.*/class Solution {public:string getPermutation(int n, int k) {int i, j, f = 1;string s(n, '0');for (i = 1;i <= n;i++) {f *= i;s[i - 1] += i;}for (i = 0, k--; i < n; i++) {f /= n - i;j = i + k / f;char c = s[j];for (;j > i;j--) {s[j] = s[j - 1];}k %= f;s[i] = c;}return s;}};
0 0
- Leetcode 60. Permutation Sequence (Medium) (cpp)
- 60. Permutation Sequence -Medium
- [Leetcode 60, Medium] Permutation Sequence
- Leetcode 31. Next Permutation (Medium) (cpp)
- LeetCode-60-Permutation Sequence(找规律)-Medium
- leetcode 日经贴,Cpp code -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
- linux 新建快捷方式
- Top K Frequent Elements
- HTTP-请求、响应、缓存
- 项目管理PV、EV、AC、BAC、EAC、ETC等计算
- Gson使用入门——初级篇
- Leetcode 60. Permutation Sequence (Medium) (cpp)
- GeoGebra入门之一分钟制作光的反射动态仿真模拟课件
- About LFU cache and LRU cache
- 一起talk C栗子吧(第一百九十一回:C语言实例--文件定位四 )
- openfire4.04编译后,浏览器中登录控制台部分乱码
- [Q学习]16 Qt状态机框架——共享状态迁移
- Hibernate基础:快速入门(1):概要及准备
- SSD训练与数据集方面的要点
- 用flask开发个人博客(7)—— flask中设置和获取cookie