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)

  

class Solution {
public:
bool check(string s){
if(atoi(s.c_str()) > ) return false;
if(s.size() > && s[] == '')return false;
return true;
}
void dfs(string s, vector<string> &cur){
if(cur.size() == ){
if(s.size() >= &&check(s)){
cur.push_back(s);
res.push_back(cur[]+'.'+cur[]+'.'+cur[]+'.'+cur[]);
cur.pop_back();
}
return ;
} for(int i = ; i <= && i <= s.size(); i++){
string temp = s.substr(,i) ;
if(check(temp)){
cur.push_back(temp);
dfs(s.substr(i,s.size()-i),cur);
cur.pop_back();
}
} }
vector<string> restoreIpAddresses(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
res.clear();
if(s.size()> || s.size() <) return res;
vector<string> cur;
dfs(s,cur);
return res;
}
private:
vector<string> res;
};

LeetCode_Restore IP Addresses的更多相关文章

  1. 【leetcode】Restore IP Addresses

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

  2. 保留ip: Reserved IP addresses

    Reserved IP addresses From Wikipedia, the free encyclopedia     In the Internet addressing architect ...

  3. 93. Restore IP Addresses

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

  4. 93.Restore IP Addresses(M)

    93.Restore IP Addresses Medium 617237FavoriteShare Given a string containing only digits, restore it ...

  5. 亚马逊 AWS ip反向解析:Configurable Reverse DNS for Amazon EC2’s Elastic IP Addresses

    I’d like to call your attention to a new feature that we rolled out earlier this month. You can now ...

  6. "cni0" already has an IP address different from 10.244.2.1/24。 Error while adding to cni network: failed to allocate for range 0: no IP addresses available in range set: 10.244.2.1-10.244.2.254

    "cni0" already has an IP address different from 10.244.2.1/24. Error while adding to cni n ...

  7. IP addresses in C#

    在.Net网络库里面最大的优点就是IP地址和端口被成对处理,相比于UNIX中用的方法真是一个巨大的令人欢迎的进步..NET定义了两个类来处理关于IP地址的问题. One of the biggest ...

  8. 【LeetCode】93. Restore IP Addresses

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

  9. LeetCode: Restore IP Addresses 解题报告

    Restore IP Addresses My Submissions Question Solution Given a string containing only digits, restore ...

随机推荐

  1. sigaction

    概述编辑 sigaction(查询或设置信号处理方式) 相关函数 signal,sigprocmask() ,sigpending,sigsuspend, sigemptyset 表头文件 #incl ...

  2. linux串口驱动分析——发送数据

    一.应用程序中write函数到底层驱动历程 和前文提到的一样,首先先注册串口,使用uart_register_driver函数,依次分别为tty_register_driver,cdev_init函数 ...

  3. bzoj4096 [Usaco2013 dec]Milk Scheduling

    Description Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which ta ...

  4. HDU_2045——RPG问题,递推

    Problem Description 人称“AC女之杀手”的超级偶像LELE最近忽然玩起了深沉,这可急坏了众多“Cole”(LELE的粉丝,即"可乐"),经过多方打探,某资深Co ...

  5. 广州Uber优步司机奖励政策(12月28日到1月3日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  6. java中文件操作的工具类

    代码: package com.lky.pojo; import java.io.BufferedReader; import java.io.BufferedWriter; import java. ...

  7. python 学习资料

    Python是一种面向对象.直译式计算机程序设计语言.它的语法简捷和清晰,尽量使用无异义的英语单词,与其它大多数程序设计语言使用大括号不一样,它使用縮进来定义语句块.与Scheme.Ruby.Perl ...

  8. 替换IMG

    <?php $str = '<img src="http://img01.feiniu.com/images/show/detail/image/20141031/9b3bbc3 ...

  9. Linux菜鸟学习笔记--Linux系统结构

      什么是Linux? Linux是一种自由和开放源码的类Unix操作系统,存在着许多不同的Linux版本,但它们都使用了Linux内核.严格来讲,Linux这个词本身只表示Linux内核,但实际上人 ...

  10. 我的Android进阶之旅------>Android安全退出应用程序的几种方式

    当应用不再使用时,通常需要关闭应用,可以使用以下几种方法关闭android应用: 第一种方法:首先获取当前进程的id,然后杀死该进程.  建议使用这种方式 android.os.Process.kil ...