File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -338,6 +338,35 @@ class Solution(object):
338
338
return ans```
339
339
```
340
340
341
+ JavaScript:
342
+
343
+ ``` js
344
+ /**
345
+ * @param {string} s
346
+ * @return {string[]}
347
+ */
348
+ var restoreIpAddresses = function (s ) {
349
+ const res = [], path = [];
350
+ backtracking (0 , 0 )
351
+ return res;
352
+ function backtracking (i ) {
353
+ const len = path .length ;
354
+ if (len > 4 ) return ;
355
+ if (len === 4 && i === s .length ) {
356
+ res .push (path .join (" ." ));
357
+ return ;
358
+ }
359
+ for (let j = i; j < s .length ; j++ ) {
360
+ const str = s .substr (i, j - i + 1 );
361
+ if (str .length > 3 || + str > 255 ) break ;
362
+ if (str .length > 1 && str[0 ] === " 0" ) break ;
363
+ path .push (str);
364
+ backtracking (j + 1 );
365
+ path .pop ()
366
+ }
367
+ }
368
+ };
369
+ ```
341
370
342
371
-----------------------
343
372
* 作者微信:[ 程序员Carl] ( https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw )
You can’t perform that action at this time.
0 commit comments