leetcode 找最長的公共子字符串前綴
class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
res = “”
right = 1
len1 = len(strs)
if len1 == 0:
return res
start = strs[0]
while right<=len(start):
for i in strs:
if start[0:right] != i[0:right]:
return res
if len(res) < right:
res = start[:right]
right+=1
return res
lecode(2)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
SGDMA與普通DMA
藍天上的雲℡
2024-05-02 14:21:20
用json來存數據的思路. json類型數據庫的思路.
張博的博客
2024-05-02 14:19:50
Vue | babel.config.js 配置詳解
emanlee
2024-05-02 14:10:29
Vue項目中main.js、App.vue、import...from...等的作用和意義
emanlee
2024-05-02 14:10:29
Vue .eslintignore
emanlee
2024-05-02 14:10:29
Vue mockjs mock.js
emanlee
2024-05-02 14:10:29
Vue .gitignore
emanlee
2024-05-02 14:10:29
vue 項目構建之 jsconfig.json 作用
emanlee
2024-05-02 14:10:29
Vue .eslintrc.js
emanlee
2024-05-02 14:10:29
Vue 生命週期 Vue進階(三十六):created() 詳解
emanlee
2024-05-02 14:10:29
Vue .browserslistrc
emanlee
2024-05-02 14:10:29
前端Vue 啓動過程 啓動流程 執行流程
emanlee
2024-05-02 14:10:29