mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
0017.电话号码的字母组合:更新Swift实现
This commit is contained in:
@ -503,7 +503,7 @@ func letterCombinations(_ digits: String) -> [String] {
|
||||
|
||||
var result = [String]()
|
||||
var s = ""
|
||||
func backtracking(digits: [Int], index: Int) {
|
||||
func backtracking(index: Int) {
|
||||
// 结束条件:收集结果
|
||||
if index == digits.count {
|
||||
result.append(s)
|
||||
@ -514,11 +514,11 @@ func letterCombinations(_ digits: String) -> [String] {
|
||||
let letters = letterMap[digits[index]]
|
||||
for letter in letters {
|
||||
s.append(letter) // 处理
|
||||
backtracking(digits: digits, index: index + 1) // 递归,记得+1
|
||||
backtracking(index: index + 1) // 递归,记得+1
|
||||
s.removeLast() // 回溯
|
||||
}
|
||||
}
|
||||
backtracking(digits: digits, index: 0)
|
||||
backtracking(index: 0)
|
||||
return result
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user