[LC] 93. Restore IP Addresses
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 List<String> restoreIpAddresses(String s) {
List<String> res = new ArrayList<>();
helper(res, 0, 0, s, "");
return res;
}
private void helper(List<String> res, int count, int index, String s, String str) {
if (count > 4) {
return;
}
if (count == 4 && index == s.length()) {
res.add(str);
}
for (int i = 1; i < 4; i++) {
if (index + i > s.length()) {
break;
}
String cur = s.substring(index, index + i);
if (cur.charAt(0) == '0' && cur.length() > 1 || cur.length() == 3 && Integer.parseInt(cur) > 255) {
continue;
}
String signal = count == 3 ? "": ".";
helper(res, count + 1, index + i, s, str + cur + signal);
}
}
}
[LC] 93. Restore IP Addresses的更多相关文章
- 93.Restore IP Addresses(M)
93.Restore IP Addresses Medium 617237FavoriteShare Given a string containing only digits, restore it ...
- 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 ...
- 93. Restore IP Addresses产生所有可能的ip地址
[抄题]: Given a string containing only digits, restore it by returning all possible valid IP address c ...
- 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 ...
- 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 ...
随机推荐
- Mac Github:第一次上传成功,解决图片不可显示,Initial commit Untracked files
在上传之前需要先给自己的电脑安装SSH 上传成功用的是github的官方提示,直接复制去做就可以了 解决README.md中图片不可显示:图片路径到底要怎么写? https://blog.csdn.n ...
- dac FDMemTable
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System ...
- 程序中出现list assignment index out of range的解决方法
class stack: def __init__(self): self.num = 0 self.elem=[] def isEmoty(self): if self.num == 0: prin ...
- day68-CSS-float浮动,clear清除浮动,overflow溢出
1. float 浮动 1.1 在 CSS 中,任何元素都可以浮动. 1.2 浮动元素会生成一个块级框,而不论它本身是何种元素.内联标签设置浮动,就变成了块级标签. 1.3 关于浮动的两个特点: 浮动 ...
- Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.postgresql.util.PSQLException: 栏位索引超过许可范围:2,栏位数:1
执行mybaits sql <delete id="delete4BatchesByLineCi" parameterType="java.util.List&qu ...
- Linux--计划任务未执行
参考:http://blog.csdn.net/shangdiyisi/article/details/9477521 日志 /var/log/cron
- Thread--volatile详细
- [Python]h5py/__init__.py:36:
个人博客地址:https://www.bearoom.xyz/2019/08/24/python-devolop-env-hdf5-problem/ 安装tensorflow之后,在导入tensorf ...
- ICRA 2019最佳论文公布 李飞飞组的研究《Making Sense of Vision and Touch: Self-Supervised Learning of Multimodal Representations for Contact-Rich Tasks》获得了最佳论文
机器人领域顶级会议 ICRA 2019 正在加拿大蒙特利尔举行(当地时间 5 月 20 日-24 日),刚刚大会公布了最佳论文奖项,来自斯坦福大学李飞飞组的研究<Making Sense of ...
- 《Docekr入门学习篇》——Docker常用命令
Docker常用命令 Docker镜像管理 搜索镜像:docker search 获取镜像:docker pull 查看镜像:docker images 删除镜像:docker rmi 构建镜像:do ...