diff --git a/leetcode/1001-1100/1079.Letter-Tile-Possibilities/README.md b/leetcode/1001-1100/1079.Letter-Tile-Possibilities/README.md index fb41ada8f..1e7f88704 100644 --- a/leetcode/1001-1100/1079.Letter-Tile-Possibilities/README.md +++ b/leetcode/1001-1100/1079.Letter-Tile-Possibilities/README.md @@ -1,28 +1,31 @@ # [1079.Letter Tile Possibilities][title] -> [!WARNING|style:flat] -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) - ## Description +You have `n` `tiles`, where each tile has one letter `tiles[i]` printed on it. + +Return the number of possible non-empty sequences of letters you can make using the letters printed on those `tiles`. **Example 1:** ``` -Input: a = "11", b = "1" -Output: "100" +Input: tiles = "AAB" +Output: 8 +Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA". ``` -## 题意 -> ... +**Example 2:** -## 题解 - -### 思路1 -> ... -Letter Tile Possibilities -```go +``` +Input: tiles = "AAABBC" +Output: 188 ``` +**Example 3:** + +``` +Input: tiles = "V" +Output: 1 +``` ## 结语 diff --git a/leetcode/1001-1100/1079.Letter-Tile-Possibilities/Solution.go b/leetcode/1001-1100/1079.Letter-Tile-Possibilities/Solution.go index d115ccf5e..c9d052aac 100644 --- a/leetcode/1001-1100/1079.Letter-Tile-Possibilities/Solution.go +++ b/leetcode/1001-1100/1079.Letter-Tile-Possibilities/Solution.go @@ -1,5 +1,23 @@ package Solution -func Solution(x bool) bool { - return x +func Solution(tiles string) int { + count := [26]int{} + for _, c := range tiles { + count[c-'A']++ + } + var dfs func() int + dfs = func() int { + r := 1 + for i := 0; i < 26; i++ { + if count[i] == 0 { + continue + } + count[i]-- + r += dfs() + count[i]++ + } + return r + + } + return dfs() - 1 } diff --git a/leetcode/1001-1100/1079.Letter-Tile-Possibilities/Solution_test.go b/leetcode/1001-1100/1079.Letter-Tile-Possibilities/Solution_test.go index 14ff50eb4..df49413a1 100644 --- a/leetcode/1001-1100/1079.Letter-Tile-Possibilities/Solution_test.go +++ b/leetcode/1001-1100/1079.Letter-Tile-Possibilities/Solution_test.go @@ -10,12 +10,12 @@ func TestSolution(t *testing.T) { // 测试用例 cases := []struct { name string - inputs bool - expect bool + inputs string + expect int }{ - {"TestCase", true, true}, - {"TestCase", true, true}, - {"TestCase", false, false}, + {"TestCase1", "AAB", 8}, + {"TestCase2", "AAABBC", 188}, + {"TestCase3", "V", 1}, } // 开始测试 @@ -30,10 +30,10 @@ func TestSolution(t *testing.T) { } } -// 压力测试 +// 压力测试 func BenchmarkSolution(b *testing.B) { } -// 使用案列 +// 使用案列 func ExampleSolution() { }