Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
# [1839.Longest Substring Of All Vowels in Order][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 string is considered **beautiful** if it satisfies the following conditions:

- Each of the 5 English vowels (`'a'`, `'e'`, `'i'`, `'o'`, `'u'`) must appear **at least once** in it.
- The letters must be sorted in **alphabetical order** (i.e. all `'a'`s before `'e'`s, all `'e'`s before `'i'`s, etc.).

For example, strings `"aeiou"` and `"aaaaaaeiiiioou"` are considered **beautiful**, but `"uaeio"`, `"aeoiu"`, and `"aaaeeeooo"` are **not beautiful**.

Given a string `word` consisting of English vowels, return the **length of the longest beautiful substring** of `word`. If no such substring exists, return `0`.

A **substring** is a contiguous sequence of characters in a string.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: word = "aeiaaioaaaaeiiiiouuuooaauuaeiu"
Output: 13
Explanation: The longest beautiful substring in word is "aaaaeiiiiouuu" of length 13.
```

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

## 题解

### 思路1
> ...
Longest Substring Of All Vowels in Order
```go
```
Input: word = "aeeeiiiioooauuuaeiou"
Output: 5
Explanation: The longest beautiful substring in word is "aeiou" of length 5.
```

**Example 3:**

```
Input: word = "a"
Output: 0
Explanation: There is no beautiful substring, so return 0.
```

## 结语

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

func Solution(x bool) bool {
return x
type charCount struct {
char byte
count int
}

func Solution(word string) int {

pre := byte(' ')
// a, e, i, o, u
group := make([]charCount, 0)
index := -1
for _, b := range []byte(word) {
if b != pre {
group = append(group, charCount{b, 1})
index++
pre = b
continue
}
group[index].count++
}
ret := 0
// 1,2,3,4,5
for i := 0; i <= len(group)-5; i++ {
if group[i].char == 'a' && group[i+1].char == 'e' && group[i+2].char == 'i' && group[i+3].char == 'o' && group[i+4].char == 'u' {
ret = max(ret, group[i].count+group[i+1].count+group[i+2].count+group[i+3].count+group[i+4].count)
}
}
return ret
}
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", "aeiaaioaaaaeiiiiouuuooaauuaeiu", 13},
{"TestCase2", "aeeeiiiioooauuuaeiou", 5},
{"TestCase3", "a", 0},
}

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

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

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