证女友(TX)# Piebridge - 鹊桥
j*3
1 楼
convert keypad numbers to all possible words.
input: str. return: list of string
for example:
'8474833' -> [ ['VISITED'], ['THRIVED'], ... ]
问时间复杂度:exponential time.O(3^n) or O(4^n)
follow up 1:返回list of breakable words.
for instance:
'3278227' -> [ ['FAST','CAR'], ['DART', 'BAR'], ['EAR', 'TABS'], ... ]
时间来不及了,没来得及做。应该就是dfs+backtracking.
follow up 2: 如何优化。答 用prefix/trie
不出意外 基本是挂了,之前没做过这题,确实有点生疏。
其实并不难。
input: str. return: list of string
for example:
'8474833' -> [ ['VISITED'], ['THRIVED'], ... ]
问时间复杂度:exponential time.O(3^n) or O(4^n)
follow up 1:返回list of breakable words.
for instance:
'3278227' -> [ ['FAST','CAR'], ['DART', 'BAR'], ['EAR', 'TABS'], ... ]
时间来不及了,没来得及做。应该就是dfs+backtracking.
follow up 2: 如何优化。答 用prefix/trie
不出意外 基本是挂了,之前没做过这题,确实有点生疏。
其实并不难。