Restore IP Addresses

Given a string containing only digits, restore it by returning all possible valid IP address combinations.
For example:
Given "25525511135",
return ["255.255.11.135", "255.255.111.35"]. (Order does not matter)
Here I use similar approach (DFS) to Palindrome Partitioning problem. Note that 
1. we should pre-check the length of the string, if it is larger than 12 or less than 4, it cannot be a valid IP address. Without this pre-checking, the following code will not pass the large judge.
2. "00" is not a valid part of IP address.

Comments

Popular posts from this blog

Maximum Gap

[ITint5] Maximum Subarray for a Circular Array

[CC150] Chapter 4 Trees and Graphs