You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Letter Combinations of a Phone Number (LeetCode)
4
4
sidebar_label: 0017 Letter Combinations of a Phone Number
5
5
tags:
6
-
- Back Tracking
7
-
- Mapping
8
-
- String
6
+
- Back Tracking
7
+
- Mapping
8
+
- String
9
9
description: The problem requires generating all letter combinations corresponding to given digits (2-9). The solution utilizes backtracking to explore all combinations efficiently, employing a recursive approach in Java.
10
-
sidebar_position: 17
11
10
---
12
11
13
12
## Problem Description
14
13
15
-
| Problem Statement | Solution Link | LeetCode Profile|
|[Letter Combinations of a Phone Number](https://leetcode.com/problems/Letter Combinations of a Phone Number/) |[Letter Combinations of a Phone Number Solution on LeetCode](https://leetcode.com/problems/Letter Combinations of a Phone Number/solutions/5055810/video-two-pointer-solution/) |[gabaniyash846](https://leetcode.com/u/gabaniyash846/)|
14
+
| Problem Statement | Solution Link | LeetCode Profile |
|[Letter Combinations of a Phone Number](https://leetcode.com/problems/Letter Combinations of a Phone Number/) |[Letter Combinations of a Phone Number Solution on LeetCode](https://leetcode.com/problems/Letter Combinations of a Phone Number/solutions/5055810/video-two-pointer-solution/) |[gabaniyash846](https://leetcode.com/u/gabaniyash846/)|
18
17
19
18
### Problem Description
20
19
21
20
## Problem Statement:
22
-
23
21
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.
24
22
25
23
### Examples
@@ -34,6 +32,7 @@ Given a string containing digits from 2-9 inclusive, return all possible letter
34
32
-**Input:**`digits = ""`
35
33
-**Output:**`[]`
36
34
35
+
37
36
#### Example 3
38
37
39
38
-**Input:**`2`
@@ -48,11 +47,9 @@ Given a string containing digits from 2-9 inclusive, return all possible letter
48
47
### Approach
49
48
50
49
1.**Mapping Digits to Letters:**
51
-
52
50
- Define a mapping of digits to their corresponding letters, similar to telephone buttons.
53
51
54
52
2.**Backtracking Function:**
55
-
56
53
- Define a recursive backtracking function to generate all possible combinations.
57
54
- The function takes four parameters:
58
55
-`index`: The current index in the digits string.
@@ -62,7 +59,6 @@ Given a string containing digits from 2-9 inclusive, return all possible letter
62
59
- After the recursive call, we remove the last character from the combination (backtracking).
63
60
64
61
3.**Base Case:**
65
-
66
62
- If the length of the current combination is equal to the length of the input digits string, we add the combination to the result list.
0 commit comments