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. kill,killall,top,free,vmstat,iostat,watch命令

    kill命令 Linux 中的kill命令用来终止指定的进程(terminate a process)的运行,是Linux下进程管理的常用命令.通常,终止一个前台进程可以 使用Ctrl+C键,但是,对 ...

  2. U-Boot启动过程完全分析

    U-Boot启动过程完全分析 1.1       U-Boot工作过程 U-Boot启动内核的过程可以分为两个阶段,两个阶段的功能如下: (1)第一阶段的功能 硬件设备初始化 加载U-Boot第二阶段 ...

  3. Linux系统编程(32)—— socket编程之TCP服务器与客户端

    TCP协议的客户端/服务器程序的一般流程 服务器调用socket().bind().listen()完成初始化后,调用accept()阻塞等待,处于监听端口的状态,客户端调用socket()初始化后, ...

  4. win7 共享

    1.取得IP 3. 输入 用户名  和密码就可以了

  5. java中的浮点(float)运算

    一.  关于浮点运算,需要说明的几点: 1.  在java中,进行浮点运算并不会处理例外情况,所以,即使除数为0,也不会有例外被抛出; 2.  当运算结果是溢出(Infinity)时,结果为Infin ...

  6. IP地址分类及特殊IP地址

    A类:0xxx xxxx.x.x.x/8,即1~127,共126个可用. 因0.x.x.x表示所有网络:127.x.x.x/8用作回环地址,作为测试TCP/IP协议的地址. =>其中10.x.x ...

  7. weblogic 的应用 常见问题处理 db2 链接不上(转载)

    xingkaistart weblogic10之Failed to initialize the application 'wss-1-1' due to error weblogic. Weblog ...

  8. Python NTLK资料

    1.Creating a new corpus with NLTK http://stackoverflow.com/questions/4951751/creating-a-new-corpus-w ...

  9. lesson5:Condition的原理分析及demo展示

    Condition 将 Object 监视器方法(wait,notify,和notifyAll)分解成截然不同的对象,以便通过将这些对象与任意Lock实现组合使用,为每个对象提供多个等待 set(wa ...

  10. Apache+Subversion+TortoiseSVN

    Key words: dav_svn, apache, subversion, tortoisesvn # install apache2 sudo apt-get install libapache ...