93_Restore IP Address
[Medium]
Given a string containing only digits, restore it by returning all possible valid IP address combinations.
Example:
Solution 1: iterative
Idea:
Loop over all possible placements of three periods, and check if all four corresponding substring are between 0 and 255.
If a substring has length larger than 1 and starts with 0, this substring is invalid.
Time Complexity: where n is the length of input string.
Space Complexity: No extra space needed except the output.
Solution 2: backtracking
Last updated