当前位置:网站首页>Analog volume leetcode [normal] 093. Restore IP address
Analog volume leetcode [normal] 093. Restore IP address
2022-07-29 06:56:00 【Encounter simulation volume】
Summary : Simulation volume Leetcode Summary of questions
093. Restore IP Address
It works IP Address It's just four integers ( Each integer is located in 0 To 255 Between the composition of , And it can't contain leading 0), Use... Between integers ‘.’ Separate .
for example :“0.1.2.201” and “192.168.1.1” yes It works IP Address , however “0.011.255.245”、“192.168.1.312” and “[email protected]” yes Invalid IP Address .
Given a string containing only numbers s , It is used to indicate a IP Address , Returns all possible valid IP Address , These addresses can be accessed through s Insert ‘.’ To form . you You can't Reorder or delete s Any number in . You can press whatever Return the answers in order .
Example 1:
Input :s = “25525511135”
Output :[“255.255.11.135”,“255.255.111.35”]
Example 2:
Input :s = “0000”
Output :[“0.0.0.0”]
Example 3:
Input :s = “101023”
Output :[“1.0.10.23”,“1.0.102.3”,“10.1.0.23”,“10.10.2.3”,“101.0.2.3”]
Tips :
1 <= s.length <= 20
s It's just numbers
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/restore-ip-addresses
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Code :
from leetcode_python.utils import *
def isLegal(ssss):
if any(s.startswith('0') for s in ssss):return False
return all(0<=int(s)<=255 for s in ssss)
class Solution:
def restoreIpAddresses(self, s: str) -> List[str]:
l = len(s)
if l<4:return []
res = []
for id1 in range(1,l-2):
for id2 in range(id1+1,l-1):
for id3 in range(id2+1,l):
ssss = [s[:id1],s[id1:id2],s[id2:id3],s[id3:]]
if isLegal(ssss):
res.append('.'.join(*ssss))
return res
def test(data_test):
s = Solution()
data = data_test # normal
# data = [List2Node(data_test[0])] # list turn node
return s.getResult(*data)
def test_obj(data_test):
result = [None]
obj = Solution(*data_test[1][0])
for fun, data in zip(data_test[0][1::], data_test[1][1::]):
if data:
res = obj.__getattribute__(fun)(*data)
else:
res = obj.__getattribute__(fun)()
result.append(res)
return result
if __name__ == '__main__':
datas = [
[],
]
for data_test in datas:
t0 = time.time()
print('-' * 50)
print('input:', data_test)
print('output:', test(data_test))
print(f'use time:{
time.time() - t0}s')
remarks :
GitHub:https://github.com/monijuan/leetcode_python
CSDN Summary : Simulation volume Leetcode Summary of questions
You can add QQ Group communication :1092754609
leetcode_python.utils See the description on the summary page for details
First brush questions , Then generated by script blog, If there is any mistake, please leave a message , I see it will be revised ! thank you !
边栏推荐
- Software definition boundary SDP
- Enterprise manager cannot connect to the database instance in Oracle10g solution
- Teacher wangshuyao's notes on operations research 03 KKT theorem
- Embedding理解+代码
- Pytorch多GPU条件下DDP集群分布训练实现(简述-从无到有)
- 如何优雅的写 Controller 层代码?
- 联邦学习后门攻击总结(2019-2022)
- 猜数字//第一次使用生成随机数
- JVM之垃圾回收机制(GC)
- 实战!聊聊如何解决MySQL深分页问题
猜你喜欢

MySQL:当你CRUD时BufferPool中发生了什么?十张图就能说清楚

【论文阅读 | cryoET】Gum-Net:快速准确的3D Subtomo图像对齐和平均的无监督几何匹配

MySQL: what happens in the bufferpool when you crud? Ten pictures can make it clear

猜数字//第一次使用生成随机数

游戏资产的革命

Neuralcf neural collaborative filtering network

Etcd principle

Understanding of access, hybrid and trunk modes

【冷冻电镜入门】加州理工公开课课程笔记 Part 3: Image Formation

【论文阅读】TomoAlign: A novel approach to correcting sample motion and 3D CTF in CryoET
随机推荐
【备忘】关于ssh为什么会失败的原因总结?下次记得来找。
模拟卷Leetcode【普通】081. 搜索旋转排序数组 II
SS command details
王树尧老师运筹学课程笔记 08 线性规划与单纯形法(单纯形法)
Unity免费元素特效推荐
Talk about tcp/ip protocol? And the role of each layer?
Let the computer run only one program setting
N2 interface of 5g control plane protocol
多线程并发下的指令重排问题
王树尧老师运筹学课程笔记 03 KKT定理
Teacher wangshuyao's notes on operations research 03 KKT theorem
王树尧老师运筹学课程笔记 10 线性规划与单纯形法(关于检测数与退化的讨论)
如何优雅的写 Controller 层代码?
【讲座笔记】如何在稀烂的数据中做深度学习?
Navicat for Oracle Cannot create oci environment
【经验】通过跳板机远程连接内网服务器的相关配置
Understanding of access, hybrid and trunk modes
Teacher Wu Enda's machine learning course notes 04 multiple linear regression
线程 - 线程安全 - 线程优化
偏向锁、轻量级锁测试工具类级相关命令