We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 545be8a commit cde15a2Copy full SHA for cde15a2
kotlin/0093-restore-ip-addresses.kt
@@ -0,0 +1,22 @@
1
+class Solution {
2
+ fun restoreIpAddresses(s: String): List<String> {
3
+ val res = mutableListOf<String>()
4
+
5
+ fun backTrack(i: Int, dots: Int, cur: String) {
6
+ if (dots == 4 && i == s.length) {
7
+ res.add(cur.substring(0, cur.lastIndex))
8
+ return
9
+ }
10
+ if (dots > 4) return
11
12
+ for (j in i until minOf(i + 3, s.length)) {
13
+ val digits = s.substring(i, j + 1)
14
+ if (digits.toInt() <= 255 && (i == j || s[i] != '0'))
15
+ backTrack(j + 1, dots + 1, cur + digits + ".")
16
17
18
19
+ backTrack(0, 0, "")
20
+ return res
21
22
+}
0 commit comments