更新 0017.电话号码的字母组合 排版格式修复

This commit is contained in:
jinbudaily
2023-07-24 11:11:15 +08:00
parent f30fd2982b
commit 87b215dd2e

View File

@ -21,12 +21,12 @@
说明:尽管上面的答案是按字典序排列的,但是你可以任意选择答案输出的顺序。
# 算法公开课
## 算法公开课
**《代码随想录》算法视频公开课:[还得用回溯算法!| LeetCode17.电话号码的字母组合](https://www.bilibili.com/video/BV1yV4y1V7Ug),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[还得用回溯算法!| LeetCode17.电话号码的字母组合](https://www.bilibili.com/video/BV1yV4y1V7Ug),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
# 思路
## 思路
从示例上来说,输入"23"最直接的想法就是两层for循环遍历了吧正好把组合的情况都输出了。
@ -40,7 +40,7 @@
2. 两个字母就两个for循环三个字符我就三个for循环以此类推然后发现代码根本写不出来
3. 输入1 * #按键等等异常情况
## 数字和字母如何映射
### 数字和字母如何映射
可以使用map或者定义一个二维数组例如string letterMap[10],来做映射,我这里定义一个二维数组,代码如下:
@ -59,7 +59,7 @@ const string letterMap[10] = {
};
```
## 回溯法来解决n个for循环的问题
### 回溯法来解决n个for循环的问题
对于回溯法还不了解的同学看这篇:[关于回溯算法,你该了解这些!](https://programmercarl.com/回溯算法理论基础.html)
@ -134,9 +134,6 @@ for (int i = 0; i < letters.size(); i++) {
**但是要知道会有这些异常,如果是现场面试中,一定要考虑到!**
## C++代码
关键地方都讲完了,按照[关于回溯算法,你该了解这些!](https://programmercarl.com/回溯算法理论基础.html)中的回溯法模板不难写出如下C++代码:
@ -233,7 +230,7 @@ public:
所以大家可以按照版本一来写就可以了。
# 总结
## 总结
本篇将题目的三个要点一一列出,并重点强调了和前面讲解过的[77. 组合](https://programmercarl.com/0077.组合.html)和[216.组合总和III](https://programmercarl.com/0216.组合总和III.html)的区别,本题是多个集合求组合,所以在回溯的搜索过程中,都有一些细节需要注意的。
@ -241,10 +238,10 @@ public:
# 其他语言版本
## 其他语言版本
## Java
### Java
```Java
class Solution {
@ -286,7 +283,7 @@ class Solution {
}
```
## Python
### Python
回溯
```python
class Solution:
@ -435,7 +432,7 @@ class Solution:
## Go
### Go
主要在于递归中传递下一个数字
@ -470,7 +467,7 @@ func dfs(digits string, start int) {
}
```
## javaScript
### JavaScript
```js
var letterCombinations = function(digits) {
@ -497,7 +494,7 @@ var letterCombinations = function(digits) {
};
```
## TypeScript
### TypeScript
```typescript
function letterCombinations(digits: string): string[] {
@ -531,7 +528,7 @@ function letterCombinations(digits: string): string[] {
};
```
## Rust
### Rust
```Rust
const map: [&str; 10] = [
@ -563,7 +560,7 @@ impl Solution {
}
```
## C
### C
```c
char* path;
@ -625,7 +622,7 @@ char ** letterCombinations(char * digits, int* returnSize){
}
```
## Swift
### Swift
```swift
func letterCombinations(_ digits: String) -> [String] {
@ -666,7 +663,7 @@ func letterCombinations(_ digits: String) -> [String] {
}
```
## Scala:
### Scala
```scala
object Solution {
@ -702,3 +699,4 @@ object Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>