Restore IP Addresses
Given a string s of only digits, return all possible valid IPv4 addresses formed by inserting three dots so the string splits into four parts. Each part must be between 0 and 255, cannot have a leading zero (unless it is exactly '0'), and no digits may be added, removed, or reordered.
Open official problem prompt ↗Enumerate every way to punctuate the digit string into four legal IPv4 octets.
Slicing a fixed loaf into exactly four pieces where each piece must weigh within an allowed range; you try each cut position and discard slicings that break a rule.
- Input
- s = "25525511135"
- Output
- ["255.255.11.135","255.255.111.35"]
- Why
- Both split the 11 digits into four parts each in 0-255 with no leading zeros; no other dot placement is valid.
1 <= s.length <= 20s consists of digits only