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的更多相关文章

  1. [LintCode] Restore IP Address 复原IP地址

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  2. LeetCode:Restore IP Address

    93. Restore IP Addresses Given a string containing only digits, restore it by returning all possible ...

  3. [Leetcode] restore ip address 存储IP地址

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  4. [LeetCode] Restore IP Address [28]

    题目 Given a string containing only digits, restore it by returning all possible valid IP address comb ...

  5. [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 ...

  6. [LeetCode] Restore IP Addresses 复原IP地址

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  7. 【leetcode】Restore IP Addresses

    Restore IP Addresses Given a string containing only digits, restore it by returning all possible val ...

  8. 【leetcode】Restore IP Addresses (middle)

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  9. LeetCode(93) Restore IP Addresses

    题目 Given a string containing only digits, restore it by returning all possible valid IP address comb ...

随机推荐

  1. delphi版本修改PE头源码

    //VC++6外衣 1 OEPCODEFIVE: THEAD = ($55, $8B, $EC, $6A, $FF, $68, $00, $00, $00, $00, $68, $00, $00, $ ...

  2. C#编程(七十四)----------释放非托管资源

    释放非托管资源 在介绍释放非托管资源的时候,我觉得有必要先来认识一下啥叫非托管资源,既然有非托管资源,肯定有托管资源. 托管资源指的是.net可以自棕进行回收的资源,主要是指托管堆上分配的内存资源.托 ...

  3. WordPress主题开发实例:查询单篇文章

    xxx/?page_id=5 想在首页调用以上页面的内容怎么做呢? 完整: <?php //查询 $my_query = new WP_Query( 'page_id=5' ); if($my_ ...

  4. Oracle 备份、恢复单表或多表数据步骤

    Oracle 备份.恢复单表或多表数据步骤,适用于 Oracle 8.9.10.        *备份单表或多表数据: exp user/password@server file=filefullpa ...

  5. 技术人生:special considerations that are very important

    For the most part, a lot of what we know about software development can be applied to different envi ...

  6. VisualStudio: Vistual Studio XML 智能提示(转载)

    原文地址:http://blog.csdn.net/hispring/article/details/5332312. 开发中经常遇到要和各种各样的 XML 打交道,编辑 XML 文件时最头痛的便是要 ...

  7. iOS酷炫动画效果合集

    iOS酷炫动画效果合集 源码地址 https://github.com/YouXianMing/Animations 效果绝对酷炫,包含了多种多样的动画类型,如POP.Easing.粒子效果等等,虽然 ...

  8. Java并发编程的艺术(六)——线程间的通信

    多条线程之间有时需要数据交互,下面介绍五种线程间数据交互的方式,他们的使用场景各有不同. 1. volatile.synchronized关键字 PS:关于volatile的详细介绍请移步至:Java ...

  9. User guide for Netty 4.x

    Table of Contents Preface The Solution Getting Started Before Getting Started Writing a Discard Serv ...

  10. maven清理.lastUpdated文件maven清理下载失败的jar,方便重新下载

    因网络或其他的原因,maven下载jar等文件失败后,会在目录中存在  *.jar.lastUpdated ,如:xmlpull-1.1.3.1.jar.lastUpdated,此时,代码编译时会一直 ...