当前位置:网站首页>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 !
边栏推荐
- Hongke share | let you have a comprehensive understanding of "can bus error" (III) -- can node status and error counter
- Teacher wangshuyao wrote the notes of operations research course 00 in the front
- Recurrent neural network RNN
- 数仓建模,什么是宽表?如何设计?好处与不足
- NeuralCF-神经协同过滤网络
- 线程同步—— 生产者与消费者、龟兔赛跑、双线程打印
- N2 interface of 5g control plane protocol
- Jetpack Compose 中的键盘处理
- Ping principle
- 吴恩达老师机器学习课程笔记 00 写在前面
猜你喜欢

【冷冻电镜|论文阅读】A feature-guided, focused 3D signal permutation method for subtomogram averaging

线程 - 线程安全 - 线程优化

The core of openresty and cosocket

Ali gave several SQL messages and asked how many tree search operations need to be performed?

SDN topology discovery principle

【讲座笔记】如何在稀烂的数据中做深度学习?

新同事写了几段小代码,把系统给搞崩了,被老板爆怼一顿!

JMM memory model concept

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

Teacher wangshuyao's operations research course notes 07 linear programming and simplex method (standard form, base, base solution, base feasible solution, feasible base)
随机推荐
STP spanning tree principle and example of election rules
吴恩达老师机器学习课程笔记 02 单变量线性回归
Shallow reading of shared lock source code of abstractqueuedsynchronizer (AQS)
The difference between pairs and ipairs
Execution sequence of finally and return
吴恩达老师机器学习课程笔记 03 线性代数回顾
如何优雅的写 Controller 层代码?
【冷冻电镜】Relion4.0——subtomogram教程
Loss function -- cross entropy loss function
竣达技术 | 适用于”日月元”品牌UPS微信云监控卡
Hongke share | bring you a comprehensive understanding of "can bus error" (II) -- can error types
Neuralcf neural collaborative filtering network
Dbasql interview questions
MySql基础知识(高频面试题)
Share some tips for better code, smooth coding and improve efficiency
吴恩达老师机器学习课程笔记 05 Octave教程
Unity探索地块通路设计分析 & 流程+代码具体实现
Teacher wangshuyao's operations research course notes 07 linear programming and simplex method (standard form, base, base solution, base feasible solution, feasible base)
【冷冻电镜|论文阅读】emClarity:用于高分辨率冷冻电子断层扫描和子断层平均的软件
Use of callable