func main() {
n, k := 0, 0
str := ""
fmt.Scan(&n, &k, &str)
ans := ""
count := 0
for len(str) > 0 {
i, s := find(k-count, str)
count++
ans += s
str = str[i+1:]
if count == k {
break
}
}
fmt.Println(ans)
}
func find(index int, str string) (i int, s string) {
for i := 0; i < 26; i++ {
in := strings.IndexByte(str, byte('z'-i))
if in+index-1 < len(str) && in != -1 {
return in, string(byte('z' - i))
}
}
return 0, ""
}
给定一个字符串,找到长度为n的字典序最大的子串
最新推荐文章于 2024-01-26 17:41:57 发布