Skip to content

Add solution and test-cases for problem 3136 #1260

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
54 changes: 42 additions & 12 deletions leetcode/3101-3200/3136.Valid-Word/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,58 @@
# [3136.Valid Word][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
A word is considered **valid** if:

- It contains a **minimum** of 3 characters.
- It contains only digits (0-9), and English letters (uppercase and lowercase).
- It includes **at least** one **vowel**.
- It includes **at least** one **consonant**.

You are given a string `word`.

Return `true` if `word` is valid, otherwise, return `false`.

**Notes**:

- `'a'`, `'e'`, `'i'`, `'o'`, `'u'`, and their uppercases are **vowels**.
- A **consonant** is an English letter that is not a vowel.


**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: word = "234Adas"

Output: true

Explanation:

This word satisfies the conditions.
```

## 题意
> ...
**Example 2:**

## 题解
```
Input: word = "b3"

Output: false

Explanation:

### 思路1
> ...
Valid Word
```go
The length of this word is fewer than 3, and does not have a vowel.
```

**Example 3:**

```
Input: word = "a3$e"

Output: false

Explanation:

This word contains a '$' character and does not have a consonant.
```

## 结语

Expand Down
27 changes: 25 additions & 2 deletions leetcode/3101-3200/3136.Valid-Word/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
package Solution

func Solution(x bool) bool {
return x
func isVowel(b byte) bool {
return b == 'a' || b == 'e' || b == 'i' || b == 'o' || b == 'u' ||
b == 'A' || b == 'E' || b == 'I' || b == 'O' || b == 'U'
}

func Solution(word string) bool {
if len(word) < 3 {
return false
}
a, c := false, false
for _, b := range []byte(word) {
if b >= '0' && b <= '9' {
continue
}
if (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') {
if isVowel(b) {
a = true
} else {
c = true
}
continue
}
return false
}
return a && c
}
12 changes: 6 additions & 6 deletions leetcode/3101-3200/3136.Valid-Word/Solution_test.go
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
inputs string
expect bool
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", "234Adas", true},
{"TestCase2", "b3", false},
{"TestCase3", "a3$e", false},
}

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

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

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