"123"
"132"
"213"
"231"
"312"
"321"

1 <= n <= 9
1 <= k <= n!

## 代码和注释详解 ：

``````class Solution {
public String getPermutation(int n, int k) {
StringBuilder sb = new StringBuilder();
List<Integer> candidates = new ArrayList<>();
int[] factorials = new int[n + 1];
factorials[0] = 1;
int fact = 1;
for (int i = 1; i <= n; ++i) {
//将元素依次存入集合candidates
//计算阶乘
fact *= i;
//把i 对应的i！存入到factorials[i]
factorials[i] = fact;
}
//第几个和集合元素下标对应
k -= 1;
for (int i = n-1; i >=0 ; --i) {
//取目标序列的索引
//如输入的k=3，n=3，则2/6=2,即取下标为2的序列
int index = k / factorials[i];
//从candidates中移除目标序列，并添加在结果字符串中
sb.append(candidates.remove(index));
k -= index*factorials[i];
};
return sb.toString();
}
}``````

## 原题链接：241. 为运算表达式设计优先级

((2-1)-1) = 0
(2-(1-1)) = 2

(2*(3-(4*5))) = -34
((2*3)-(4*5)) = -14
((2*(3-4))*5) = -10
(2*((3-4)*5)) = -10
(((2*3)-4)*5) = 10

1 <= expression.length <= 20
expression 由数字和算符 '+'、'-' 和 '*' 组成
输入表达式中的所有整数值在范围 [0, 99]

## 代码和注释详解 ：

``````class Solution {
public List<Integer> diffWaysToCompute(String expression) {
//定义集合存储可能的结果
List<Integer> list = new ArrayList<>();
//获取字符串的长度
int len = expression.length();
int start = 0;
for (start = 0; start < len; start++) {
//判断是否为纯数字
if(Character.isDigit(expression.charAt(start))) continue;
else break;
}
//start==len 则意味着全为数字没有符号，直接转义存储到list中
if(start==len) {
}
//遍历字符串
for (int i = start; i < len; i++) {
//获取索引i上的字符
char op = expression.charAt(i);
//判断字符是否为运算符
if(op=='+'||op=='-'||op=='*'){
//分而治之
List<Integer> left = diffWaysToCompute(expression.substring(0,i));//运算符左边部分
List<Integer> right = diffWaysToCompute(expression.substring(i+1,len));//运算符右边部分

//最后再把运算符左右两边的结果同运算符计算存储到list中
for (int j : left){
for (int k : right){
}
}
}
}
return list;
}
}``````