LintCode: Restore IP Address
C++
string::substr(start_pos, length)
vector::push_back(element)
class Solution {
public:
vector<string> restoreIpAddresses(string s) {
vector<string> ret;
if(s.size() > )
return ret;
for(int i = ; i < s.size(); i ++)
{// [0, i]
string ip1 = s.substr(, i+);
if ( !check(ip1) ) break;
for(int j = i+; j < s.size(); j ++)
{// [i+1, j]
string ip2 = s.substr(i+, j-i);
if ( !check(ip2) ) break;
for(int k = j+; k < s.size()-; k ++)
{// [j+1, k], [k+1, s.size()-1]
string ip3 = s.substr(j+, k-j);
string ip4 = s.substr(k+);
if(check(ip3) && check(ip4))
{
string ip = ip1 + "." + ip2 + "." + ip3 + "." + ip4;
ret.push_back(ip);
}
}
}
}
return ret;
}
bool check(string ip)
{
int value = stoi(ip);
if(ip[] == '') return ip.size() == ;
return value <= ? true : false;
}
};
LintCode: Restore IP Address的更多相关文章
- [LintCode] Restore IP Address 复原IP地址
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- LeetCode:Restore IP Address
93. Restore IP Addresses Given a string containing only digits, restore it by returning all possible ...
- [Leetcode] restore ip address 存储IP地址
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- [LeetCode] Restore IP Address [28]
题目 Given a string containing only digits, restore it by returning all possible valid IP address comb ...
- [LeetCode] Validate IP Address 验证IP地址
In this problem, your job to write a function to check whether a input string is a valid IPv4 addres ...
- [LeetCode] Restore IP Addresses 复原IP地址
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- 【leetcode】Restore IP Addresses
Restore IP Addresses Given a string containing only digits, restore it by returning all possible val ...
- 【leetcode】Restore IP Addresses (middle)
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- LeetCode(93) Restore IP Addresses
题目 Given a string containing only digits, restore it by returning all possible valid IP address comb ...
随机推荐
- SMTP协议及POP3协议-邮件发送和接收原理(转)
本文转自https://blog.csdn.net/qq_15646957/article/details/52544099 感谢作者 一. 邮件开发涉及到的一些基本概念 1.1.邮件服务器和电子邮箱 ...
- linux服务器使用iftop查看带宽流量IP
20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送) 国内私募机构九鼎控股打造,九鼎投资是在全国股 ...
- C#编程(六十三)----------并行LINQ
并行LINQ .NET4在System.Linq命名空间中包含一个新类ParallelEnumerable,可以分解查询的工作使其分布在多个线程上.尽管Enumerable类给IEnumerable& ...
- 【转】IntelliJ IDEA关联SVN
http://blog.csdn.net/xdd19910505/article/details/52756417 问题描述: IntelliJ IDEA安装之后,使用SVN进行提交或更新以及检出代码 ...
- CentOS安装sctp协议
转自:http://blog.csdn.net/fly_yr/article/details/48375247 序 最近学习Unix网络编程,在第10章节,SCTP客户/服务器 程序实现时,发现很多由 ...
- FZU2169:shadow(最短路)
Problem Description YL是shadow国的国王,shadow国有N个城市.为了节省开支,shadow国仅仅有N-1条道路,这N-1条道路使得N个城市连通. 某一年,shadow国发 ...
- 用wifi来调试应用程序
我们一般调试程序都是用的adb,这个adb其实是可以连接到某个端口的,只要我们的手机和电脑处于同一wifi环境下(你可以用电脑分出来的wifi),手机也接入同一端口就可以实现程序的无线调试了,终于可以 ...
- Logstash使用jdbc_input同步Mysql数据时遇到的空时间SQLException问题
今天在使用Logstash的jdbc_input插件同步Mysql数据时,本来应该能搜索出10条数据,结果在Elasticsearch中只看到了4条,终端中只给出了如下信息 [2017-08-25T1 ...
- [转]PHP与Shell交互
From : http://blog.csdn.net/houqd2012/article/details/8219199 最近想使用PHP与Sheel进行交互.PHP控制显示和高层的逻辑结构.She ...
- MVC详解(转)
原文链接:MVC详解 MVC与模板概念的理解 MVC(Model View Controller)模型-视图-控制器 MVC本来是存在于Deskt op程序中的,M是指数据模型,V是指用户界面,C ...