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 ...
随机推荐
- 用C扩展Python3
官方文档: https://docs.python.org/3/extending/index.html 交叉编译到aarch64上面 以交叉编译到aarch64上面为例,下面是Extest.c的实现 ...
- 委托、Lambda表达式、事件系列03,从委托到Lamda表达式
在"委托.Lambda表达式.事件系列02,什么时候该用委托"一文中,使用委托让代码简洁了不少. namespace ConsoleApplication2 { internal ...
- poi workbook转成流
try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); workbook.write(bos); byte[] barray = ...
- 使用集成SOA网关的PL / SQL中的REST
使用集成SOA网关的PL / SQL中的REST Oracle电子商务套件集成SOA网关(ISG)是一款开箱即用的模块,支持在Oracle Integration Repository中发布支持的接口 ...
- jquery.jCal.js显示日历插件
描述:日历插件jCal用于需要输入日期的表单文本框. 兼容浏览器:IE浏览器/Firefox/Google Chrome 官方链接: http://www.overset.com/2008/05/1 ...
- Unity3D 中鼠标按下时OnMouseDown()、Input.GetMouseButtonDown()和EventType.MouseDown的响应验证
初学unity3D,对于其中的事件响应不是很清楚,于是写了下面的代码来验证: 1.新建.cs文件,名为testMouse.cs: using UnityEngine; using System.Col ...
- [Android Pro] 终极组件化框架项目方案详解
cp from : https://blog.csdn.net/pochenpiji159/article/details/78660844 前言 本文所讲的组件化案例是基于自己开源的组件化框架项目g ...
- C#和java之间的一些差异与共性
C#与java之间的一些共性和差异整理 隐藏:与java中的重写几乎一致,但是需要添加new关键字让编译器知道,否则会有警告 虚方法:1.声明为virtual的方法就是虚方法,在子类中使用overri ...
- webrequest HttpWebRequest webclient/HttpClient
webrequest(abstract类,不可直接用) <--- (继承)---- HttpWebRequest(更好的控制请求) <--- (继承)---- webclient (简单快 ...
- eclipse的块选择模式
第一步:Alt+shift+a打开Toggle Block Selection Mode(块选择模式开关) 第二步:点击Toggle Block Selection 第三步:选择多行,同时编辑