Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1fba09e

Browse files
Marsh RoydenMarsh Royden
Marsh Royden
authored and
Marsh Royden
committed
add solution for 17. Letter Combinations of a Phone Number in Kotlin
1 parentb3e34f1 commit1fba09e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
packagekotlin
2+
3+
classSolution {
4+
funletterCombinations(digits:String):List<String> {
5+
if (digits.isEmpty())return emptyList()
6+
val resultantList= mutableListOf<String>()
7+
val stringBuilder=StringBuilder()
8+
val digitCharListMapping=mutableMapOf(
9+
'2' tolistOf('a','b','c'),
10+
'3' tolistOf('d','e','f'),
11+
'4' tolistOf('g','h','i'),
12+
'5' tolistOf('j','k','l'),
13+
'6' tolistOf('m','n','o'),
14+
'7' tolistOf('p','q','r','s'),
15+
'8' tolistOf('t','u','v'),
16+
'9' tolistOf('w','x','y','z')
17+
)
18+
19+
fundfs(decisionIndex:Int = 0) {
20+
if (stringBuilder.length== digits.length) {
21+
resultantList.add(stringBuilder.toString())
22+
return
23+
}
24+
val charListForDigitAtDecisionIndex= digitCharListMapping.getValue(digits[decisionIndex])
25+
for (charin charListForDigitAtDecisionIndex) {
26+
stringBuilder.append(char)
27+
dfs(decisionIndex+1)
28+
stringBuilder.deleteCharAt(stringBuilder.lastIndex)
29+
}
30+
}
31+
dfs()
32+
return resultantList
33+
}
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp