Skip to content
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

Add solution and test-cases for problem 3223 #1093

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
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
# [3223.Minimum Length of String After Operations][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 are given a string `s`.

You can perform the following process on `s` **any** number of times:

- Choose an index `i` in the string such that there is **at least** one character to the left of index `i` that is equal to `s[i]`, and **at least** one character to the right that is also equal to `s[i]`.
- Delete the **closest** character to the **left** of index `i` that is equal to `s[i]`.
- Delete the **closest** character to the **right** of index `i` that is equal to `s[i]`.

Return the **minimum** length of the final string `s` that you can achieve.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
```
Input: s = "abaacbcbb"

## 题意
> ...
Output: 5

## 题解
Explanation:
We do the following operations:

### 思路1
> ...
Minimum Length of String After Operations
```go
Choose index 2, then remove the characters at indices 0 and 3. The resulting string is s = "bacbcbb".
Choose index 3, then remove the characters at indices 0 and 5. The resulting string is s = "acbcb".
```

**Example 2:**

```
Input: s = "aa"

Output: 2

Explanation:
We cannot perform any operations, so we return the length of the original string.
```

## 结语

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
package Solution

func Solution(x bool) bool {
return x
func Solution(s string) int {
count := [26]int{}
for _, b := range s {
count[b-'a']++
}
ans := 0
for i := range 26 {
if count[i] != 0 {
if count[i]&1 == 1 {
ans++
continue
}
ans += 2
}
}
return ans
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ 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", "abaacbcbb", 5},
{"TestCase2", "aa", 2},
}

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

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

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