Skip to content

Add solution and test-cases for problem 3330 #1248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions leetcode/3301-3400/3330.Find-the-Original-Typed-String-I/README.md
Original file line number Diff line number Diff line change
@@ -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
```

## 结语

Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}

// 开始测试
Expand All @@ -30,10 +30,10 @@ func TestSolution(t *testing.T) {
}
}

// 压力测试
// 压力测试
func BenchmarkSolution(b *testing.B) {
}

// 使用案列
// 使用案列
func ExampleSolution() {
}
Loading