Leetcode 暑期bb班

495 回覆
251 Like 31 Dislike
2022-05-30 21:40:09
玩咗leetcode 都幾年 通常轉工先拎出嚟練陣
但每次隔太耐 都係重做返以前做過果啲(仲要失哂憶) 到而家200條都冇
2022-05-30 23:11:02
屎忽痕做咗easy第一題,即係integer of list(unsorted) find the relative indexes of two sum of a target number個題,個腦知要點做(首先開個for loop, 順序pick一個number i,然後copy剩低嘅list再做sort,然後就用binary search 去搵target - i,最後就Return返各自嘅index),但因為syntax 唔熟係咁出error,做咗成個鐘先冇bug

仲有一點好黐線,就係有人個runtime好Q快, 又有d人Memory用得好少,都唔知點做到
2022-05-30 23:12:54
唔做leetcode 都唔覺heap 咁好用
2022-05-30 23:15:45
Two sum
2022-05-30 23:59:29
Heap sort 都算熱門嘢嘅
2022-05-31 00:54:58
counter有most_common() 入面有機會用heap
2022-05-31 05:13:07
過多幾個禮拜先玩graph
2022-05-31 05:15:23
easy第一題係 2 sum?
你個方法都work到,不過binary search唔熟嘅話好容易寫錯
binary search唔係optimal,因為時間係nlogn
你可以試下用dictionary做
2022-05-31 06:23:24
幾時做下recusion 同 dynamic programming
2022-05-31 07:07:58
比較後先做
2022-05-31 12:38:10
真係work,但唔知點解個run time仲慢咗
2022-05-31 13:29:24
# another solution, use set

class Solution(object):
def containsDuplicate(self, nums):
a = set()
for x in nums:
if x in a:
return True
else:
a.add(x)
return False
2022-05-31 15:38:23
想請問下, python有無得改個comparator
2022-05-31 18:53:41
有既,不過唔係咁寫法啫。
記得有一個問題,佢既solution 發表左一番議論。

佢話以前interview 多數直接問你電腦知識,而家就將呢啲知識融入左coding question 入面,如果你對某個範疇有認識(例如file system, scheduler, image processing 之類)就會睇得出條問題既algorithm 用係邊度,而有insight 好快做到。。。
2022-05-31 20:42:13
leetcode runtime is a bit on9, don't be bothered haha
2022-05-31 20:42:24
yes set is better for this problem
2022-05-31 20:43:04
2022-05-31 20:49:34
Day 5 review (heap)

https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/
呢題最簡單可以用sort做,不過我地個topic係用heap
loop每一個row,數有幾多個1,之後heappush (用max heap,因為我地想pop最大嘅數)
如果個heap多過k行,就heappop
最後heappop返攞答案,再reverse
2022-05-31 20:50:42
Day 6 (Heap)

https://leetcode.com/problems/k-closest-points-to-origin/
https://leetcode.com/problems/minimum-operations-to-halve-array-sum/

再做兩條medium,試下用heap做,記住max heap係要用負數
2022-05-31 21:22:41
2022-05-31 21:30:25
逐個column上至下左至右scan咪得
最先見到0果行最weak, 第i行見到0 第i weak
唔明點解要咁執著用heap somewhere
2022-05-31 21:31:54
你係咪唔識linear time selection?
吹水台自選台熱 門最 新手機台時事台政事台World體育台娛樂台動漫台Apps台遊戲台影視台講故台健康台感情台家庭台潮流台美容台上班台財經台房屋台飲食台旅遊台學術台校園台汽車台音樂台創意台硬件台電器台攝影台玩具台寵物台軟件台活動台電訊台直播台站務台黑 洞