mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2026-02-02 18:39:09 +08:00
Merge branch 'master' into master
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
<p align="center">
|
||||
<a href="https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ"><img src="https://img.shields.io/badge/知识星球-代码随想录-blue" alt=""></a>
|
||||
<a href="https://mp.weixin.qq.com/s/RsdcQ9umo09R6cfnwXZlrQ"><img src="https://img.shields.io/badge/PDF下载-代码随想录-blueviolet" alt=""></a>
|
||||
<a href="https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw"><img src="https://img.shields.io/badge/刷题-微信群-green" alt=""></a>
|
||||
<a href="https://img-blog.csdnimg.cn/20201210231711160.png"><img src="https://img.shields.io/badge/公众号-代码随想录-brightgreen" alt=""></a>
|
||||
<a href="https://space.bilibili.com/525438321"><img src="https://img.shields.io/badge/B站-代码随想录-orange" alt=""></a>
|
||||
<a href="https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ"><img src="https://img.shields.io/badge/知识星球-代码随想录-blue" alt=""></a>
|
||||
</p>
|
||||
<p align="center"><strong>欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
|
||||
<p align="center"><strong>欢迎大家<a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
|
||||
|
||||
|
||||
# 17.电话号码的字母组合
|
||||
@@ -272,7 +272,7 @@ class Solution {
|
||||
String str = numString[digits.charAt(num) - '0'];
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
temp.append(str.charAt(i));
|
||||
//回溯
|
||||
//c
|
||||
backTracking(digits, numString, num + 1);
|
||||
//剔除末尾的继续尝试
|
||||
temp.deleteCharAt(temp.length() - 1);
|
||||
@@ -282,6 +282,7 @@ class Solution {
|
||||
```
|
||||
|
||||
Python:
|
||||
|
||||
```Python
|
||||
class Solution:
|
||||
ans = []
|
||||
@@ -316,6 +317,28 @@ class Solution:
|
||||
self.s = self.s[:-1] # 回溯
|
||||
```
|
||||
|
||||
python3:
|
||||
|
||||
```python3
|
||||
class Solution:
|
||||
def letterCombinations(self, digits: str) -> List[str]:
|
||||
self.s = ""
|
||||
res = []
|
||||
letterMap = ["","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"]
|
||||
if len(digits) == 0: return res
|
||||
def backtrack(digits,index):
|
||||
if index == len(digits):
|
||||
return res.append(self.s)
|
||||
digit = int(digits[index]) #将index指向的数字转为int
|
||||
letters = letterMap[digit] #取数字对应的字符集
|
||||
for i in range(len(letters)):
|
||||
self.s += letters[i]
|
||||
backtrack(digits,index + 1) #递归,注意index+1,一下层要处理下一个数字
|
||||
self.s = self.s[:-1] #回溯
|
||||
backtrack(digits,0)
|
||||
return res
|
||||
```
|
||||
|
||||
|
||||
Go:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user