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 ...
随机推荐
- 百度贴吧的网络爬虫(v0.4)源码及解析
更新:感谢评论中朋友的提醒,百度贴吧现在已经改成utf-8编码了吧,需要把代码中的decode('gbk')改成decode('utf-8'). 百度贴吧的爬虫制作和糗百的爬虫制作原理基本相同,都 ...
- 2015第29周五AOP
AOP使用场景 AOP用来封装横切关注点,具体可以在下面的场景中使用: Authentication 权限 Caching 缓存 Context passing 内容传递 Error handling ...
- JFreeChart学习
一.步骤: 创建数据集(准备数据) 根据数据集生成JFreeChart对象,并对其做相应的设置(标题,图例,x轴,Y轴,对象渲染等) 将JFreeChart对象输出到文件或者Servlet输出流等 二 ...
- Jmeter接口测试-badboy录制脚本(二)
1.脚本录制,采用badboy进行录制,操作步骤很简单 2.badboy简介: Badboy是一款免费WEB自动化测试工具. 官方下载地址:http://www.badboy.com.au badbo ...
- cavium octeon 处理器启动总线Bootbus 简介
cavium octeon 处理器启动总线Bootbus 简介: 韩大卫@吉林师范大学 Boot-bus(启动总线)是cavium octeon处理器的一种用于启动系统的硬件. CPU通过boot b ...
- RedHat下GCC及G++的安装
GCC的安装: 切换到安装光盘目录下: #mount /dev/cdrom /mnt/cdrom #cd /mnt/cdrom 安装GCC依赖的*rpm程序,必须按照顺序依次执行: #rpm - ...
- swift和oc混编
请参考这篇博客:点击查看
- 自定义key解决zabbix端口监听取值不准确的问题
今天有一个朋友问到我一个关于zabbix监控tcp端口的问题,明明端口在监听,但是通过net.tcp,listen取值取到的却是0. 经过简单的goole发现这已经是一个历史悠久的问题: 问 ...
- NHibernate之映射文件配置说明(转载3)
十二.组件(component), 动态组件(dynamic-component) <component>元素把子对象的一些元素与父类对应的表的一些字段映射起来. 然后组件可以定义它们自己 ...
- WPF资源字典使用
资源字典出现的初衷就在于可以实现多个项目之间的共享资源,资源字典只是一个简单的XAML文档,该文档除了存储希望使用的资源之外,不做任何其它的事情. 1. 创建资源字典 创建资源字典的过程比较简单,只 ...