Update 0541.反转字符串II.md

去掉 continue,增加 else 分支,逻辑更加清晰
This commit is contained in:
Harrytsz 2022-05-26 16:35:42 +08:00 committed by GitHub
parent 91399c3aae
commit 36a1d71201
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -53,10 +53,10 @@ public:
// 2. 剩余字符小于 2k 但大于或等于 k 个,则反转前 k 个字符
if (i + k <= s.size()) {
reverse(s.begin() + i, s.begin() + i + k );
continue;
} else {
// 3. 剩余字符少于 k 个,则将剩余字符全部反转。
reverse(s.begin() + i, s.end());
}
// 3. 剩余字符少于 k 个,则将剩余字符全部反转。
reverse(s.begin() + i, s.begin() + s.size());
}
return s;
}