diff --git a/problems/0131.分割回文串.md b/problems/0131.分割回文串.md index f4d72eea..84a5bd02 100644 --- a/problems/0131.分割回文串.md +++ b/problems/0131.分割回文串.md @@ -575,12 +575,9 @@ func partition(_ s: String) -> [[String]] { for i in startIndex ..< s.count { // 回文则收集,否则跳过 - if isPalindrome(start: startIndex, end: i) { - let substring = String(s[startIndex ... i]) - path.append(substring) - } else { - continue - } + guard isPalindrome(start: startIndex, end: i) else { continue } + let substring = String(s[startIndex ... i]) + path.append(substring) // 处理 backtracking(startIndex: i + 1) // 寻找下一个起始位置的子串 if !path.isEmpty { path.removeLast() } // 回溯 }