Skip to content

Commit

Permalink
0131.分割回文串:Swift实现优化迭代中跳过逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
bqlin committed Dec 23, 2021
1 parent 622b443 commit 690897f
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions problems/0131.分割回文串.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() } // 回溯
}
Expand Down

0 comments on commit 690897f

Please sign in to comment.