We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4b921bf commit f9346f4Copy full SHA for f9346f4
Algorithms/0126.word-ladder-ii/word-ladder-ii.go
@@ -102,18 +102,19 @@ func deepCopy(src []string) []string {
102
// 题目中说了,words 中没有重复的单词,
103
// 所以,beginWord 最多出现一次
104
func deleteBeginWord(words []string, beginWord string) []string {
105
- i := 0
106
- for ; i < len(words); i++ {
+ i, size := 0, len(words)
+ for ; i < size; i++ {
107
if words[i] == beginWord {
108
break
109
}
110
111
112
- if i == len(words) {
+ if i == size {
113
return words
114
115
116
- return append(words[:i], words[i+1:]...)
+ words[i] = words[size-1]
117
+ return words[:size-1]
118
119
120
func isTransable(a, b string) bool {
0 commit comments