93.Restore IP Addresses(M)
617237FavoriteShare
Given a string containing only digits, restore it by returning all possible valid IP address combinations.
Example:
Input: "25525511135"
Output: ["255.255.11.135", "255.255.111.35"]
class Solution {
public:
vector<string> restoreIpAddresses(string s) {
vector<string> result;
string ip;
dfs(s,,,ip,result); //paras:string s,start index of s,step(from0-3),intermediate ip,final result
return result;
}
void dfs(string s,int start,int step,string ip,vector<string>& result){
){
ip.erase(ip.end()-); //remove the last '.' from the last decimal number
result.push_back(ip);
return;
}
-step)*) return;
-step)) return;
;
;i++){
num=num*+(s[i]-');
){
ip+=s[i];
dfs(s,i+,step+,ip+'.',result);
}
) break;
}
}
};
// zjchenRice
93.Restore IP Addresses(M)的更多相关文章
- leetcode 93. Restore IP Addresses(DFS, 模拟)
题目链接 leetcode 93. Restore IP Addresses 题意 给定一段序列,判断可能组成ip数的所有可能集合 思路 可以采用模拟或者DFS的想法,把总的ip数分成四段,每段判断是 ...
- 93. Restore IP Addresses
题目: Given a string containing only digits, restore it by returning all possible valid IP address com ...
- 【LeetCode】93. Restore IP Addresses
Restore IP Addresses Given a string containing only digits, restore it by returning all possible val ...
- leetcode 93 Restore IP Addresses ----- java
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- 【一天一道LeetCode】#93. Restore IP Addresses
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 93. Restore IP Addresses产生所有可能的ip地址
[抄题]: Given a string containing only digits, restore it by returning all possible valid IP address c ...
- LeetCode OJ 93. Restore IP Addresses
题目 Given a string containing only digits, restore it by returning all possible valid IP address comb ...
- 93. Restore IP Addresses(dfs)
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- [LeetCode] 93. Restore IP Addresses 复原IP地址
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
随机推荐
- python xlrd 读取excel.md
文章链接:https://mp.weixin.qq.com/s/fojkVO-AB2cCu7FtDtPBjw 之前的文章介绍过关于写入excel表格的方法,近期自己在做一个网站,涉及到读取excel, ...
- Android View的重绘过程之Draw
博客首页:http://www.cnblogs.com/kezhuang/p/ View绘制的三部曲,测量,布局,绘画现在我们分析绘画部分测量和布局 在前两篇文章中已经分析过了.不了解的可以去我的博客 ...
- C#零基础入门-0-开发工具
Visual Studio sharpDevelop:http://www.icsharpcode.net/OpenSource/SD/Download/ Visual Studio Express
- sql面试 查找每个班级的前5名学生(取分类数据的前几条数据)
关键字PARTITION BY 自己看代码喽~ SELECT * FROM ( SELECT ROW_NUMBER() OVER (PARTITION BY ClassType ORDER BY Sc ...
- eclipse 更改默认主题,重写默认滚动条样式(安装DevStyle主题插件)
1.点击Help->Eclipse Marktplace 2.弹出窗口输入: DevStyle 3.点击安装,重启eclipse 4.可以设置黑色和浅色主题,个人比较喜欢浅色,重点式滚动条样式变 ...
- crontab的笔试题随想
最近看到一道题目,具体如下: 下列哪个是创建一个每周三01:00~04:00每3分钟执行一次的crontab指令? A: 1,4 3 /bin/bash /home/sijiaomao/ok.sh B ...
- 4.16 反射和jvm
- 《JAVA程序设计》_第八周学习总结
一.学习内容 1.泛型类声明--15.1知识 可以使用"class 名称"声明一个类,为了和普通的类有所区别,这样声明的类称作泛型类,如: class People<E> ...
- [十二省联考2019]D2T2春节十二响
嘟嘟嘟 这题真没想到这么简单-- 首先有60分大礼:\(O(n ^ 2logn)\)贪心.(我也不知道为啥就是对的) 然后又送15分链:维护两个堆,每次去堆顶的最大值. 这时候得到75分已经很开心了, ...
- 重大变革即将来临 5G CPE会替代光纤入户吗?
导读 从国内的新闻报道上我们可以看到,从2018年下半年开始各大重要活动.春晚直播等,都宣布已经使用5G网络.既然支持5G网络的终端都还没有正式上市,那么5G网络是如何使用的呢?答案是5G CPE设备 ...