Leetcode 暑期bb班
靜靜打J好無 2022-5-30 21:35:25 此回覆已被刪除

Ads

靜靜打J好無 2022-5-30 21:37:27 此回覆已被刪除
query123 2022-5-30 21:40:09 玩咗leetcode 都幾年 通常轉工先拎出嚟練陣
但每次隔太耐 都係重做返以前做過果啲(仲要失哂憶) 到而家200條都冇
:^(
飄移巴士 2022-5-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用得好少,都唔知點做到
:^(
勇武condom 2022-5-30 23:12:54 唔做leetcode 都唔覺heap 咁好用
:^(
項少龍 2022-5-30 23:15:45 Two sum
query123 2022-5-30 23:59:29 Heap sort 都算熱門嘢嘅
程式猿 2022-5-31 00:54:58 counter有most_common() 入面有機會用heap
:^(
裂曲風紀 2022-5-31 05:13:07 過多幾個禮拜先玩graph
裂曲風紀 2022-5-31 05:15:23 easy第一題係 2 sum?
你個方法都work到,不過binary search唔熟嘅話好容易寫錯
binary search唔係optimal,因為時間係nlogn
你可以試下用dictionary做
:^(
5識打code既IT人 2022-5-31 06:23:24 幾時做下recusion 同 dynamic programming

Ads

裂曲風紀 2022-5-31 07:07:58 比較後先做
飄移巴士 2022-5-31 12:38:10 真係work,但唔知點解個run time仲慢咗
:^(

:^(
5識打code既IT人 2022-5-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
PanzerVI 2022-5-31 15:38:23 想請問下, python有無得改個comparator
:^(
object71 2022-5-31 18:53:41 有既,不過唔係咁寫法啫。
記得有一個問題,佢既solution 發表左一番議論。

佢話以前interview 多數直接問你電腦知識,而家就將呢啲知識融入左coding question 入面,如果你對某個範疇有認識(例如file system, scheduler, image processing 之類)就會睇得出條問題既algorithm 用係邊度,而有insight 好快做到。。。
裂曲風紀 2022-5-31 20:42:13 leetcode runtime is a bit on9, don't be bothered haha
裂曲風紀 2022-5-31 20:42:24 yes set is better for this problem
裂曲風紀 2022-5-31 20:42:52 https://stackoverflow.com/questions/3766633/how-to-sort-with-lambda-in-python
裂曲風紀 2022-5-31 20:43:04
:^(
裂曲風紀 2022-5-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
:^(

Ads

裂曲風紀 2022-5-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係要用負數
ohgnoll 2022-5-31 21:22:41
:^(
連燈巴打 2022-5-31 21:30:25 逐個column上至下左至右scan咪得
最先見到0果行最weak, 第i行見到0 第i weak
唔明點解要咁執著用heap somewhere
連燈巴打 2022-5-31 21:31:54 你係咪唔識linear time selection?