係,你個方法time complexity更好
搵唔到有其他easy可以introduce heap
如果你有題目可以幫到一個做左leetcode 5日熟習heap嘅
歡迎你po上黎
Day 5 review (heap)你個solution係O(n*m)
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
Counting係O(n)
O(m log n)應該要用Binary search去probe column index
睇下邊個column多d 1