Skip to content

Commit 76cfb26

Browse files
authored
Merge pull request #1248 from 0xff-dev/3330
Add solution and test-cases for problem 3330
2 parents 30d1d1a + 50ce325 commit 76cfb26

File tree

3 files changed

+56
-21
lines changed

3 files changed

+56
-21
lines changed

leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/README.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
11
# [3330.Find the Original Typed String I][title]
22

3-
> [!WARNING|style:flat]
4-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5-
63
## Description
74

5+
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.
6+
7+
Although Alice tried to focus on her typing, she is aware that she may still have done this **at most** once.
8+
9+
You are given a string `word`, which represents the **final** output displayed on Alice's screen.
10+
11+
Return the total number of possible original strings that Alice might have intended to type.
12+
813
**Example 1:**
914

1015
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
16+
Input: word = "abbcccc"
17+
18+
Output: 5
19+
20+
Explanation:
21+
22+
The possible strings are: "abbcccc", "abbccc", "abbcc", "abbc", and "abcccc".
1323
```
1424

15-
## 题意
16-
> ...
25+
**Example 2:**
1726

18-
## 题解
27+
```
28+
Input: word = "abcd"
29+
30+
Output: 1
1931
20-
### 思路1
21-
> ...
22-
Find the Original Typed String I
23-
```go
32+
Explanation:
33+
34+
The only possible string is "abcd".
2435
```
2536

37+
**Example 3:**
38+
39+
```
40+
Input: word = "aaaa"
41+
42+
Output: 4
43+
```
2644

2745
## 结语
2846

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(word string) int {
4+
ans := 1
5+
c := 0
6+
pre := byte(' ')
7+
for _, b := range []byte(word) {
8+
if b == pre {
9+
c++
10+
continue
11+
}
12+
if c > 1 {
13+
ans += c - 1
14+
}
15+
c = 1
16+
pre = b
17+
}
18+
if c > 1 {
19+
ans += c - 1
20+
}
21+
return ans
522
}

leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/Solution_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14-
expect bool
13+
inputs string
14+
expect int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", "abbcccc", 5},
17+
{"TestCase2", "abcd", 1},
18+
{"TestCase3", "aaaa", 4},
1919
}
2020

2121
// 开始测试
@@ -30,10 +30,10 @@ func TestSolution(t *testing.T) {
3030
}
3131
}
3232

33-
// 压力测试
33+
// 压力测试
3434
func BenchmarkSolution(b *testing.B) {
3535
}
3636

37-
// 使用案列
37+
// 使用案列
3838
func ExampleSolution() {
3939
}

0 commit comments

Comments
 (0)