/* 自定義代碼塊樣式 */

herrDeng網內搜尋

自訂搜尋

Ads

2024年3月9日 星期六

C++雙指標與二元搜尋解Leetcode 2540 Minimum Common Value


C++雙指標與二元搜尋解Leetcode 2540  Minimum Common Value
陣列已排序。 使用雙指標或使用二元搜尋找來解它
第二種方法使用二分搜索,當 n1 或 n2 非常大時另外一個數很小時,這種方法非常有效。

2024年3月8日 星期五

python C C++陣列迴圈速解Leetcode 3005 Count Elements With Maximum Frequency


python C C++陣列迴圈速解Leetcode 3005  Count Elements With Maximum Frequency
陣列迴圈就能解答的,何須用到hash table(C++ unordered_map)簡單的問題可用簡單的 資料結構解答,迴圈就是迴圈、陣列就是陣列(內有python code)

2024年3月3日 星期日

python C C++速解Leetcode 19 Remove Nth Node From End of List並考慮memory leaks問題


python C C++速解Leetcode 19 Remove Nth Node From End of List並考慮memory leaks問題
其實刷題不要只是貪快還是要考慮Memory Leaks,解老題目19 Remove Nth Node From End of List要特別別考慮,另別是C/C++使用者

2024年3月1日 星期五

C++ 2行Python 1行解Leetcode 2864 Maximum Odd Binary Number


Leetcode 2864. Maximum Odd Binary Number問題,要想寫出一行解也不是那麼容易,C++合理的二行解、python的一行解。要點先數幾個1再重填字串,另外還有使用兩個游標的解法,未在影片中。

2024年2月22日 星期四

python C++計算 indegree解Leetcode 997 Find the Town Judge


python C++計算 indegree解Leetcode 997  Find the Town Judge
使用圖形解決方案。
由於信任中的每一對 e=(a, b) 實際上表示一種信任關係,可以將其視為有向邊。C++程式請進
---

2024年2月21日 星期三

python C++ bit 計算O(1)時間解Leetcode 201 Bitwise AND of Numbers Range


python C++ bit 計算O(1)時間解Leetcode 201  Bitwise AND of Numbers Range
這就是用x&(x-1)技法。有人會說計算時間是O(log n),但32-bit整數,無論是迴圈或遞迴頂多32次。如果要熟透bit處理的訣竅,還有更厲害的技法,請進

2024年2月20日 星期二

python C++高斯小學公式與xor sum速解Leetcode 268 Missing Number


python C++高斯小學公式與xor sum速解Leetcode 268  Missing Number
片中講兩種解法,一是用Gauss的n(n+1)/2公式,二是用xor-sum
第三種解法片中未顯示,採radix sort再binary search

2024年2月17日 星期六

C++貪婪演算與Min Heap解Leetcode 1642 Furthest Building You Can Reach

Leetcode問題1642. Furthest Building You Can Reach也是用Greedy演算,有梯子、有磚塊,要訣就是高度差大的用梯子,高度差小的用磚塊,至於容器,C++可用priority_queue或用make_heap,當然也可用multiset,用heap的解答當然很快速,千萬不要誤入歧途採用DP動態規劃,先看constraints就知。

2024年2月15日 星期四

C++, python貪婪演算解多邊形問題Leetcode 2971 Find Polygon With the Largest Perimeter


C++, python貪婪演算解多邊形問題Leetcode 2971  Find Polygon With the Largest Perimeter
程式實作不難,用貪婪演算即可,有人知其然不知所以然,貪婪演算是否可用是需要數學證明的,下面有一個用make_heap的解答,保留在此
Related Posts Plugin for WordPress, Blogger...

熱門文章