leetcode restore ip address Java实现
来源:互联网 发布:英雄联盟盒子mac版 编辑:程序博客网 时间:2024/05/29 10:09
原题目链接:
https://leetcode.com/problems/restore-ip-addresses/description/
java代码:
class Solution { public List<String> restoreIpAddresses(String s) { ArrayList<String> ips=new ArrayList<String>(); String current_ip=""; getAllIP(s,0,0,current_ip,ips); return ips; } public void getAllIP(String s,int index,int step,String current_ip,ArrayList<String> ips) { if(s.length()-index>(4-step)*3) { return; } else if(s.length()-index<4-step) { return; } else if(step==4&&index==s.length()) { ips.add(current_ip.substring(0,current_ip.length()-1)); } else { int num=0; for(int i=index;i<Math.min(index+3,s.length());i++) { num=num*10+s.charAt(i)-'0'; if(num<=255) { current_ip+=s.charAt(i); getAllIP(s,i+1,step+1,current_ip+".",ips); } if(num==0) break; } } }}
阅读全文
0 0
- leetcode restore ip address Java实现
- Leetcode Restore IP Address
- Leetcode: Restore IP Address
- [LeetCode] Restore IP Address
- LeetCode: Restore IP Address
- [leetcode] restore IP address
- leetcode Restore IP Address
- Leetcode Restore IP Address
- LeetCode:Restore IP Address
- [LeetCode] Restore IP Address [28]
- Leetcode(91) Restore IP Address
- Restore IP Address Leetcode Python
- Restore IP address
- [Leetcode] Restore IP Addresses (Java)
- [LeetCode][Java] Restore IP Addresses
- leetcode:Restore IP Addresses 【Java】
- 5th IP address restore
- 【leetcode】93. Restore IP Addresses【java】
- Spring Boot系列六 Spring boot集成mybatis、分页插件pagehelper
- js十大排序算法
- redis实现分布式锁
- AngularJS 与 Bootstrap 的结合实例
- step by step
- leetcode restore ip address Java实现
- 鼠标突然无反应,鼠标灯亮,鼠标灯不亮
- 【Socket编程】Python用udp实现简易ping
- NKOJ-4239 追捕游戏
- java 中常见 类型转换 -全面-String ,char ,char[],int 之间的转换。
- Git basic construction
- python字典的简单用法
- Spring如何实现管理Bean的。
- 大型网站架构技术一览