LeetCode_Restore IP Addresses
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的更多相关文章
- 【leetcode】Restore IP Addresses
Restore IP Addresses Given a string containing only digits, restore it by returning all possible val ...
- 保留ip: Reserved IP addresses
Reserved IP addresses From Wikipedia, the free encyclopedia In the Internet addressing architect ...
- 93. Restore IP Addresses
题目: Given a string containing only digits, restore it by returning all possible valid IP address com ...
- 93.Restore IP Addresses(M)
93.Restore IP Addresses Medium 617237FavoriteShare Given a string containing only digits, restore it ...
- 亚马逊 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 ...
- "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 ...
- IP addresses in C#
在.Net网络库里面最大的优点就是IP地址和端口被成对处理,相比于UNIX中用的方法真是一个巨大的令人欢迎的进步..NET定义了两个类来处理关于IP地址的问题. One of the biggest ...
- 【LeetCode】93. Restore IP Addresses
Restore IP Addresses Given a string containing only digits, restore it by returning all possible val ...
- LeetCode: Restore IP Addresses 解题报告
Restore IP Addresses My Submissions Question Solution Given a string containing only digits, restore ...
随机推荐
- COJ 0020 30201象棋中的皇后
30201象棋中的皇后 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 在n×m的棋盘上放置两个相互攻击的皇后,总共有多少种不同 ...
- hdu-1800
思路: 这题被坑的不轻. 首先花了一段时间想明白了思路是要找出现次数最多数字,以为这题就这样解决了,结果发现每个数字的最大长度是30,long long都装不下,因此就要用字符串来保存处理.然后在in ...
- AES的S-BOX构造优化
之前写过SBOX的构造,后来看到别人的优秀思路,借鉴过来重新改了一点. 原文地址:http://www.cnblogs.com/7hat/p/3383546.html 主要是将矩阵运算改为列运算之和, ...
- Stooge排序
又叫臭皮匠排序... 在<算法导论>作为反例出现的漂亮但极其低效的排序算法. 基本思路是:只要数组长度大于3,先将头与尾排序,然后递归调用排序前三分之二,再递归调用排序后三分之二,最后再递 ...
- javascript表单验证-邮箱验证
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- spring xml记录
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2 ...
- UINavigation push 于 present到另一个页面详解
如果页面中没有导航栏,可以present到这个A页面,在A页面想要跳转到有个有导航栏的页面就需要添加给B页面添加一个UINavigationController 然后present到B页面,代码如下 ...
- VS2010旗舰版安装图解
微软公布了最新的 Visual Studio 2010 软件开发编程平台及 .Net Framework 4 框架.这次 VisualStudio 2010 包含 Professional 专业版.P ...
- 解决从github下载web的源代码部署到eclipse的问题
2015年6月2日 天气晴 github官网:https://github.com/ 以下以pdf.js作为案例说明:https://github.com/mozilla/pdf.js 1).点击案例 ...
- Java基础知识强化65:基本类型包装类之Integer的构造方法
1. Integer类概述 (1)Integer类在对象中包装了一个基本类型 int 的值,Integer类型的对象包含一个int类型的字段. (2)该类提供了多个方法,能在int类型和String类 ...