#93
Restore IP Addresses
specialist · 800 · lc medium +31 · verified · 55.4% accepted · 5,633 likes · top 49%
Description
A valid IPv4 address consists of four integers in [0, 255] separated by dots, with no leading zeros other than "0" itself. Given digit-only string s, return all valid IP addresses obtainable by inserting exactly three dots without reordering or removing any character. Results may be in any order.
Example 1:
Input: s = "25525511135"
Output: ["255.255.11.135","255.255.111.35"]
Example 2:
Input: s = "0000"
Output: ["0.0.0.0"]
Example 3:
Input: s = "101023"
Output: ["1.0.10.23","1.0.102.3","10.1.0.23","10.10.2.3","101.0.2.3"]
Code
1
2
3