-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17.js
More file actions
38 lines (35 loc) · 731 Bytes
/
17.js
File metadata and controls
38 lines (35 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* @param {string} digits
* @return {string[]}
*/
var letterCombinations = function (digits) {
if (digits.length === 0) return []
let c = [["a", "b", "c"],
["d", "e", "f"],
["g", "h", "i"],
["j", "k", "l"],
["m", "n", "o"],
["p", "q", "r", "s"],
["t", "u", "v"],
["w", "x", "y", "z"]]
let res = []
let track = []
const bt = start => {
if (start === digits.length) {
res.push(track.join(''))
return
}
c[digits[start] - 2].forEach(e => {
track.push(e)
bt(start + 1)
track.pop()
})
}
bt(0)
return res
}
/*
2021/10/28
67 50
回溯
*/