
Leetcode(93): Restore IP Addresses
发布日期:2021-05-15 10:07:10
浏览次数:17
分类:博客文章
本文共 1065 字,大约阅读时间需要 3 分钟。
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)
1 public class Solution { 2 public ListrestoreIpAddresses(String s) { 3 List res=new ArrayList (); 4 if(s.length()<4||s.length()>12) return res; 5 dfs(s,"",res,0); 6 return res; 7 } 8 public static void dfs(String s,String temp,List list,int count){ 9 if(count==3&&isValid(s)){10 list.add(temp+s);11 return;12 }13 for(int i=1;i<4&&i 0;25 }26 public static void main(String[] args) {27 // TODO Auto-generated method stub28 Scanner sc=new Scanner(System.in);29 solution sl=new solution();30 31 List list=sl.restoreIpAddresses(sc.next());32 33 for(String i:list){34 System.out.println(i);35 }36 }37 38 }
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2025年04月14日 20时26分55秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Spring cloud --分布式配置中心组件Spring Cloud Config
2019-03-12
UE4接入Android第三方库2——通过JIN与GameActivity通信
2019-03-12
Unity Job System 2——并行处理数据
2019-03-12
spark概述
2019-03-12
JavaScript 知识梳理[一] 变量类型,浅拷贝,深拷贝
2019-03-12
pip命令 failed to create process.
2019-03-12
做SMTP客户端遇报错:535 Error
2019-03-12
Python3的修改
2019-03-12
SQL基础学习(六)- MySQL的insert语句
2019-03-12
Linux kernel pwn --- CSAW2015 StringIPC
2019-03-12
2020 05 02 记录思考
2019-03-12
2020-05-31 py执行时超时控制
2019-03-12
一段强大的shellcode
2019-03-12
双链表相加问题
2019-03-12
GB2312-80 汉字机内码
2019-03-12
n的a进制数
2019-03-12
配置jdk的环境变量
2019-03-12
echo命令的颜色及同行显示控制
2019-03-12
CentOS7利用Systemd添加用户自定义系统服务
2019-03-12