2138. Divide a String Into Groups of Size k
A string s can be partitioned into groups of size k using the following procedure:
The first group consists of the first k characters of the string, the second group consists of the next k characters of the string, and so on. Each character can be a part of exactly one group.
For the last group, if the string does not have k characters remaining, a character fill is used to complete the group.
以下golang code
func divideString(s string, k int, fill byte) []string {
result := []string{}
for i := 0; i < len(s); i += k {
if i+k <= len(s) {
result = append(result, s[i:i+k])
continue
}
str := s[i:len(s)]
for len(str) < k {
str += string(fill)
}
result = append(result, str)
}
return result
}
每天记忆都会重置
都要在append这里卡一下==
然后if else的排版错了(换个行之类)就会直接编译不过
有点神奇
然后有办法在宣告一个 指定最大长度,但长度是0的slice吗