Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5bd0248

Browse files
Update 0093.复原IP地址.md
加入了python3,更类似于LeetCode131题代码的写法,看起来更简洁些
1 parent 4b9d902 commit 5bd0248

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎problems/0093.复原IP地址.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,30 @@ class Solution:
424424
return True
425425
```
426426

427+
python3; 简单拼接版本(类似Leetcode131写法):
428+
```python
429+
class Solution:
430+
def restoreIpAddresses(self, s: str) -> List[str]:
431+
global results, path
432+
results = []
433+
path = []
434+
self.backtracking(s,0)
435+
return results
436+
437+
def backtracking(self,s,index):
438+
global results,path
439+
if index == len(s) and len(path)==4:
440+
results.append('.'.join(path)) # 在连接时需要中间间隔符号的话就在''中间写上对应的间隔符
441+
return
442+
for i in range(index,len(s)):
443+
if len(path)>3: break # 剪枝
444+
temp = s[index:i+1]
445+
if (int(temp)<256 and int(temp)>0 and temp[0]!='0') or (temp=='0'):
446+
path.append(temp)
447+
self.backtracking(s,i+1)
448+
path.pop()
449+
```
450+
427451
## Go
428452

429453
```go

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /