leetcode Question 83: Restore IP Addresses
2015-01-24 02:57
344 查看
Restore IP Addresses:
Given a string containing only digits, restore it by returning all possible valid IP address combinations.
For example:
Given
return
Analysis:
This problem can be viewed as a DP problem. There needed 3 dots to divide the string, and make sure the IP address is valid:
less than or equal to 255, greater or equal to 0, and note that, "0X" or "00X" is not valid.
For the DP, the length of each part is from 1 to 3. We use a vector<string> to store each part, and cut the string every
time. Details see the code.
Note that "atoi" is for c-string, <string> need to convert to cstring by str.c_str();
?
Code(old version):
?
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)
Analysis:
This problem can be viewed as a DP problem. There needed 3 dots to divide the string, and make sure the IP address is valid:
less than or equal to 255, greater or equal to 0, and note that, "0X" or "00X" is not valid.
For the DP, the length of each part is from 1 to 3. We use a vector<string> to store each part, and cut the string every
time. Details see the code.
Note that "atoi" is for c-string, <string> need to convert to cstring by str.c_str();
Code(Updated 201309):
??
相关文章推荐
- [LeetCode] 086: Restore IP Addresses
- Leetcode--Restore IP Addresses
- [LeetCode]Restore IP Addresses
- Leetcode Restore IP Addresses
- leetcode:Restore IP Addresses
- LeetCode 93 Restore IP Addresses
- [leetcode]Restore IP Addresses
- LeetCode题解:Restore IP Addresses
- 【LeetCode】Restore IP Addresses
- LeetCode: My solution:Restore IP Addresses
- LeetCode-Restore IP Addresses
- LeetCode Online Judge 题目C# 练习 - Restore IP Addresses
- [Leetcode] Restore IP Addresses (Java)
- [Leetcode] Restore IP Addresses
- LeetCode | Restore IP Addresses(恢复ip地址)
- [leetcode] Restore IP Addresses
- 【leetcode】Restore IP Addresses
- LeetCode-93-Restore IP Addresses 暴力
- LeetCode93——Restore IP Addresses
- leetcode - Restore IP Addresses