题目描述
你有一套活字字模 tiles,其中每个字模上都刻有一个字母 tiles[i]。返回你可以印出的非空字母序列的数目。
示例:
输入:“AAB”
输出:8
解释:可能的序列为 “A”, “B”, “AA”, “AB”, “BA”, “AAB”, “ABA”, “BAA”。
总结
SC 回溯的题有些用数学是投机取巧,但有些不是,是6
SC2 就是抽象出来,不在乎实际排列出来是什么字符串,而是 计数 判断
Sample Code 1 (不理解)
class Solution {
public int numTilePossibilities(String tiles) {
char[] chars = tiles.toCharArray();
Arrays.sort(chars);
return helper(0, 1, 1, 1, new int[26], chars);
}
private int helper(int start, int a, int b, int m, int[] counts, char[] chars) {
int result = 0;
a *= m;
for (int i = start; i <