060.Permutation Sequence Posted on 2017-09-16 | In LeetCode Test cases12349544949171669 Solution 1: tle123456789101112131415161718192021222324252627282930class Solution { public String getPermutation(int n, int k) { if (n < 1 || k < 1) { return null; } List<String> result = new ArrayList<>(); StringBuilder sb = new StringBuilder(); permuteHelper(result, sb, n, k); return result.get(k - 1).toString(); } public void permuteHelper(List<String> result, StringBuilder sb, int n, int k) { if (result.size() < k) { if (sb.length() == n) { result.add(sb.toString()); } else { for (int i = 1; i <= n; i++) { if (sb.indexOf(i + "") < 0) { sb.append(i + ""); permuteHelper(result, sb, n); sb.setLength(sb.length() - 1); } } } } }}