Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add solution and test-cases for problem 1805 #1273

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

Merged
6boris merged 1 commit into 6boris:main from 0xff-dev:1805
Aug 3, 2025
Merged
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
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
# [1805.Number of Different Integers in a String][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 `word` that consists of digits and lowercase English letters.

You will replace every non-digit character with a space. For example, `"a123bc34d8ef34"` will become `" 123 34 8 34"`. Notice that you are left with some integers that are separated by at least one space: `"123"`, `"34"`, `"8"`, and `"34"`.

Return the number of **different** integers after performing the replacement operations on `word`.

Two integers are considered different if their decimal representations **without any leading zeros** are different.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: word = "a123bc34d8ef34"
Output: 3
Explanation: The three different integers are "123", "34", and "8". Notice that "34" is only counted once.
```

## 题意
> ...

## 题解
**Example 2:**

### 思路1
> ...
Number of Different Integers in a String
```go
```
Input: word = "leet1234code234"
Output: 2
```

**Example 3:**

```
Input: word = "a1b01c001"
Output: 1
Explanation: The three integers "1", "01", and "001" all represent the same integer because
the leading zeros are ignored when comparing their decimal values.
```

## 结语

Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
package Solution

func Solution(x bool) bool {
return x
func Solution(word string) int {
count := make(map[string]struct{})
firstMeet := true
foundNumber := false
start := -1
for i, b := range word {
if b >= '0' && b <= '9' {
foundNumber = true
if firstMeet && b == '0' {
continue
}
if start == -1 {
start = i
}
firstMeet = false
continue
}
if foundNumber {
if start == -1 {
count["0"] = struct{}{}
} else {
count[word[start:i]] = struct{}{}
}
}
foundNumber = false
firstMeet = true
start = -1
}
if foundNumber {
if start == -1 {
count["0"] = struct{}{}
} else {
count[word[start:]] = struct{}{}
}
}
return len(count)
}
View file Open in desktop
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", "a123bc34d8ef34", 3},
{"TestCase2", "leet1234code234", 2},
{"TestCase3", "a1b01c001", 1},
}

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

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

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

AltStyle によって変換されたページ (->オリジナル) /