* * @param {number} i * @param {number} dots * @param {string} currentIP
(i, dots, currentIP)
| 14 | * @param {string} currentIP |
| 15 | */ |
| 16 | function backtracking(i, dots, currentIP) { |
| 17 | if (dots === 4 && i == s.length) { |
| 18 | res.push(currentIP.slice(0, currentIP.length - 1)); |
| 19 | return; |
| 20 | } else if (dots > 4) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | for (let j = i; j < Math.min(i + 3, s.length); j++) { |
| 25 | if (+s.slice(i, j + 1) < 256 && (i == j || s[i] != '0')) { |
| 26 | backtracking( |
| 27 | j + 1, |
| 28 | dots + 1, |
| 29 | currentIP + s.slice(i, j + 1) + '.', |
| 30 | ); |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | backtracking(0, 0, ''); |
| 36 |
no test coverage detected