python leetcode 93. Restore IP Addresses
又是DFS
class Solution(object):
def restoreIpAddresses(self, s):
"""
:type s: str
:rtype: List[str]
"""
self.res=set()
def help(s1,s2,k):
if s2=="" and k==0:
return self.res.add(s1[:-1])
if k<=0 or s2=="":
return
for i in range(1,4):
if 0<=int(s2[:i])<=255:
if len(s2[:i])>1 and s2[0]=='0':
break
help(s1+s2[:i]+'.',s2[i:],k-1)
help("",s,4)
return list(self.res)
相關文章
- [LeetCode] 93. Restore IP AddressesLeetCodeREST
- 「leetcode」93.復原IP地址【回溯演算法】詳解!LeetCode演算法
- LeetCode之Unique Email Addresses(Kotlin)LeetCodeAIKotlin
- [AlwaysOn2017] AlwaysOn的DMV和DMF -Sys.availability_group_listener_ip_addressesAI
- [LeetCode] Validate IP AddressLeetCode
- guarantee restore points-Flashback after RMAN restoreREST
- canvas restore()CanvasREST
- LeetCode-093-復原 IP 地址LeetCode
- canvas save()和restore()CanvasREST
- DOCKER特性 - LIVE RESTOREDockerREST
- DBMS_BACKUP_RESTORE.DBMS_BACKUP_RESTORE用於特殊情況下的恢復REST
- git操作之二:git restoreGitREST
- provider for back&restore app datyaIDERESTAPP
- 程式碼隨想錄演算法訓練營第24天 | 93.復原IP地址 78.子集 90.子集Ⅱ演算法
- LeetCode迴文數(Python)LeetCodePython
- python LeetCode 兩數相除PythonLeetCode
- Python leetcode tree記錄PythonLeetCode
- python: leetcode - 1 Two SumPythonLeetCode
- [20190228]Backup Restore Throttle sleep.txtREST
- git restore極簡使用記錄GitREST
- Crunchy PostgreSQL database restore via pgo commandSQLDatabaseRESTGo
- Reboot Restore Rx Pro中文版bootREST
- python爬蟲從ip池獲取隨機IPPython爬蟲隨機
- 05.python requests IP代理Python
- RMAN restore validate database報ORA-19693RESTDatabase
- LeetCode反轉整數(Python)LeetCodePython
- LeetCode最長公共字首(Python)LeetCodePython
- LeetCode有效的括號(Python)LeetCodePython
- LeetCode數學問題(Python)LeetCodePython
- 「LeetCode By Python」簡單篇(一)LeetCodePython
- Python向IP地址傳送字串Python字串
- python如何獲取本機ipPython
- rman 還原歸檔日誌(restore archivelogRESTHive
- db2備份恢復(backup restore)DB2REST
- leetcode刷題筆記(3)(python)LeetCode筆記Python
- LeetCode刷題(javascript,python3)LeetCodeJavaScriptPython
- LeetCode-Python-252. 會議室LeetCodePython
- 用Python爬蟲抓取代理IPPython爬蟲