File tree 2 files changed +44
-1
lines changed
2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -33,11 +33,11 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
33
33
| 54| [ Spiral Matrix] ( https://leetcode.com/problems/spiral-matrix/ ) | [ JavaScript] ( ./src/spiral-matrix/res.js ) | Medium|
34
34
| 66| [ Plus One] ( https://leetcode.com/problems/plus-one/ ) | [ JavaScript] ( ./src/plus-one/res.js ) | Easy|
35
35
| 69| [ Sqrt(x)] ( https://leetcode.com/problems/sqrtx/ ) | [ JavaScript] ( ./src/sqrtx/res.js ) | Easy|
36
-
37
36
| 71| [ Simplify Path] ( https://leetcode.com/problems/simplify-path/ ) | [ JavaScript] ( ./src/simplify-path/res.js ) | Medium|
38
37
| 73| [ Set Matrix Zeroes] ( https://leetcode.com/problems/set-matrix-zeroes/ ) | [ JavaScript] ( ./src/set-matrix-zeroes/res.js ) | Medium|
39
38
| 75| [ Sort Colors] ( https://leetcode.com/problems/sort-colors/ ) | [ JavaScript] ( ./src/sort-colors/res.js ) | Medium|
40
39
| 91| [ Decode Ways] ( https://leetcode.com/problems/decode-ways/ ) | [ JavaScript] ( ./src/decode-ways/res.js ) | Medium|
40
+ | 93| [ Restore IP Addresses] ( https://leetcode.com/problems/restore-ip-addresses/ ) | [ JavaScript] ( ./src/restore-ip-addresses/res.js ) | Medium|
41
41
| 120| [ Triangle] ( https://leetcode.com/problems/triangle/ ) | [ JavaScript] ( ./src/triangle/res.js ) | Medium|
42
42
| 130| [ Surrounded Regions] ( https://leetcode.com/problems/surrounded-regions/ ) | [ JavaScript] ( ./src/surrounded-regions/res.js ) | Medium|
43
43
| 133| [ Clone Graph] ( https://leetcode.com/problems/clone-graph/ ) | [ JavaScript] ( ./src/clone-graph/res.js ) | Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * res.js
3
+ * @authors Joe Jiang (hijiangtao@gmail.com)
4
+ * @date 2017-05-11 10:39:29
5
+ *
6
+ * @param {string } s
7
+ * @return {string[] }
8
+ */
9
+ let restoreIpAddresses = function ( s ) {
10
+ let len = s . length ,
11
+ res = [ ] ;
12
+ if ( len < 4 ) return [ ] ;
13
+
14
+ for ( let first = 1 ; first < 5 ; first ++ ) {
15
+ if ( first === len ) break ;
16
+ for ( let second = 1 ; second < 5 ; second ++ ) {
17
+ if ( first + second === len ) break ;
18
+ for ( let third = 1 ; third < 5 ; third ++ ) {
19
+ if ( first + second + third === len ) break ;
20
+ let tmp1 = s . substring ( 0 , first ) ,
21
+ tmp2 = s . substring ( first , first + second ) ,
22
+ tmp3 = s . substring ( first + second , first + second + third ) ,
23
+ tmp4 = s . substring ( first + second + third ) ;
24
+
25
+ if ( isValid ( tmp1 ) && isValid ( tmp2 ) && isValid ( tmp3 ) && isValid ( tmp4 ) ) {
26
+ res . push ( `${ tmp1 } .${ tmp2 } .${ tmp3 } .${ tmp4 } ` ) ;
27
+ }
28
+ }
29
+ }
30
+ }
31
+
32
+ return res ;
33
+
34
+ function isValid ( str ) {
35
+ if ( str . charAt ( 0 ) === '0' && str . length > 1 ) return false ;
36
+
37
+ let num = Number . parseInt ( str ) ;
38
+ if ( num < 256 )
39
+ return true ;
40
+ else
41
+ return false ;
42
+ }
43
+ } ;
You can’t perform that action at this time.
0 commit comments