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,22 @@
# [1163.Last Substring in Lexicographical 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
Given a string `s`, return the last substring of `s` in lexicographical order.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: s = "abab"
Output: "bab"
Explanation: The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab"]. The lexicographically maximum substring is "bab".
```

## 题意
> ...

## 题解
**Example 2:**

### 思路1
> ...
Last Substring in Lexicographical Order
```go
```

Input: s = "leetcode"
Output: "tcode"
```

## 结语

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

func Solution(x bool) bool {
return x
func Solution(s string) string {
indies := [26][]int{}
for i, b := range s {
indies[b-'a'] = append(indies[b-'a'], i)
}
i := 25
for ; i >= 0 && len(indies[i]) == 0; i-- {
}
ans := ""
for _, index := range indies[i] {
ans = max(ans, s[index:])
}
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 string
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", "abab", "bab"},
{"TestCase2", "leetcode", "tcode"},
}

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

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

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