LeetCode刷題之172 階乘後的零

2021-10-01 23:08:40 字數 798 閱讀 8014

我不知道將去向何方,但我已在路上!

輸入: numbers = [2, 7, 11, 15], target = 9

輸出: [1,2]

解釋: 2 與 7 之和等於目標數 9 。因此 index1 = 1, index2 = 2

class

solution

:def

twosum

(self, numbers: list[

int]

, target:

int)

-> list[

int]

: i =

0 j =

len(numbers)-1

while i < j:

if numbers[i]

+ numbers[j]

== target:

return

([i+

1,j+1]

)break

if numbers[i]

+ numbers[j]

> target:

j = j -

1if numbers[i]

+ numbers[j]

< target:

i = i +

1# 執行用時 :60 ms, 在所有 python3 提交中擊敗了50.38%的使用者

# 記憶體消耗 :13.6 mb, 在所有 python3 提交中擊敗了64.63%的使用者

leetcode刷題,總結,記錄 ,備忘 172

leetcode172 factorial trailing zeroes given an integer n,return the number of trailing zeroes in n note your solution should be in logarithmic time co...

Leetcode刷題之括號

給定乙個只包括 的字串,判斷字串是否有效。有效字串需滿足 左括號必須用相同型別的右括號閉合。左括號必須以正確的順序閉合。注意空字串可被認為是有效字串。示例 1 輸入 輸出 true 示例 2 輸入 輸出 true 示例 3 輸入 輸出 false 示例 4 輸入 輸出 false 示例 5 輸入 輸...

leetcode刷題之堆

今天終於開啟的第二個專題的刷題之旅堆,不過第乙個專題棧還有乙個小問題沒解決就是利用遞減棧去解決接雨水的問題,雖然那道題我用動態規劃的問題解決出來了,我記得看到過一道面試題,問棧和堆有什麼區別。通過搜尋網上的資料總結如下。棧 stack 由系統分配記憶體,速度較快,但是自己無法掌握。堆 一般用兩種方法...