diff --git a/leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/README.md b/leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/README.md index 21f9634d..e7c64bef 100755 --- a/leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/README.md +++ b/leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/README.md @@ -1,28 +1,46 @@ # [3330.Find the Original Typed String I][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 +Alice is attempting to type a specific string on her computer. However, she tends to be clumsy and **may** press a key for too long, resulting in a character being typed **multiple** times. + +Although Alice tried to focus on her typing, she is aware that she may still have done this **at most** once. + +You are given a string `word`, which represents the **final** output displayed on Alice's screen. + +Return the total number of possible original strings that Alice might have intended to type. + **Example 1:** ``` -Input: a = "11", b = "1" -Output: "100" +Input: word = "abbcccc" + +Output: 5 + +Explanation: + +The possible strings are: "abbcccc", "abbccc", "abbcc", "abbc", and "abcccc". ``` -## 题意 -> ... +**Example 2:** -## 题解 +``` +Input: word = "abcd" + +Output: 1 -### 思路1 -> ... -Find the Original Typed String I -```go +Explanation: + +The only possible string is "abcd". ``` +**Example 3:** + +``` +Input: word = "aaaa" + +Output: 4 +``` ## 结语 diff --git a/leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/Solution.go b/leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/Solution.go index d115ccf5..bb7bb584 100644 --- a/leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/Solution.go +++ b/leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/Solution.go @@ -1,5 +1,22 @@ package Solution -func Solution(x bool) bool { - return x +func Solution(word string) int { + ans := 1 + c := 0 + pre := byte(' ') + for _, b := range []byte(word) { + if b == pre { + c++ + continue + } + if c > 1 { + ans += c - 1 + } + c = 1 + pre = b + } + if c > 1 { + ans += c - 1 + } + return ans } diff --git a/leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/Solution_test.go b/leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/Solution_test.go index 14ff50eb..42026b42 100644 --- a/leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/Solution_test.go +++ b/leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/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", "abbcccc", 5}, + {"TestCase2", "abcd", 1}, + {"TestCase3", "aaaa", 4}, } // 开始测试 @@ -30,10 +30,10 @@ func TestSolution(t *testing.T) { } } -// 压力测试 +// 压力测试 func BenchmarkSolution(b *testing.B) { } -// 使用案列 +// 使用案列 func ExampleSolution() { }