Thursday, July 10, 2014

[Leetcode] Restore IP Addresses


Problem

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)

Algorithm

An IP address has a form
x.x.x.x
where x range from 0 to 255. Since x has a length from 1 to 3, a valid IP address should have 4 to 12 digits.

Code



No comments:

Post a Comment