herrDeng網內搜尋

自訂搜尋

Ads

2024年5月12日 星期日

python C++速解MaxPooling Leetcode 2373 Largest Local Values in a Matrix


python CPP速解MaxPooling Leetcode 2373  Largest Local Values in a Matrix
算maxPooling stride=1就一般矩陣計算而已,找出子矩陣的極大,可以只使用額外空間O(1)就得解。C++解請進。
-----

2024年5月4日 星期六

C++ python貪婪排序2 pointer解Leetcode 881 Boats to Save People


C++ python貪婪排序2 pointer解Leetcode 881  Boats to Save People
Greedy是這類問題的關鍵,片中先用sort, counting sort來排序,左有兩游標大小一對看能不能一次載兩人,逐次移動游標
-------

2024年4月29日 星期一

C++/reroot DP動態規劃解Leetcode難題834 Sum of Distances in Tree


C++/reroot DP動態規劃解Leetcode難題834  Sum of Distances in Tree
關鍵字:reroot DP。 你會發現很多關於它的討論。
對於作為根的每個節點,進行 DFS,將獲得 O(n^2) 的解決方案,但可能 TLE。
使用一次遞迴 DFS 求 root=0 的樹中的距離和,計算每個節點 i 作為根的子樹中的節點數。

2024年4月24日 星期三

C++ UnionFind BFS DFS解圖論問題Leetcode 1971 Find if Path Exists in Graph


C++ UnionFind  BFS DFS解圖論問題Leetcode 1971 Find if Path Exists in Graph
使用UnionFind class實作容易,效能又好,這對無向圖特別有效。
為了比較,BFS、DFS也實作

Python C++速解Leetcode 1137 N th Tribonacci Number


Python CPP速解Leetcode 1137  N th Tribonacci Number
先用遞迴、再加上cache,然後轉成動態規劃,當然還可以用矩陣冪次方

2024年4月20日 星期六

C++ DFS BFS貪婪三法解Leetcode農地問題1992 Find All Groups of Farmland


C++ DFS BFS貪婪三法解Leetcode農地問題1992  Find All Groups of Farmland
採用三種方式解題,一是DFS, 二是BFS,前兩法都很標準。農地因為都是矩形,第三法採貪婪演算找出矩形右下角,簡單又快速。

2024年4月16日 星期二

C++ DFS BFS解二元樹Leetcode 623 Add One Row to Tree


C++ DFS BFS解二元樹Leetcode 623 Add One Row to Tree
要辨識一位程式設計師是否會使用常用的資料結構,binary  tree就是個鑑別率高的東西,許多程式自學者壓根沒見過。Leetcode 623. Add One Row to Tree是個好練習

2024年4月14日 星期日

C++ python速解左葉節點之和Leetcode 404 Sum of Left Leaves


C++ python速解左葉節點之和Leetcode 404  Sum of Left Leaves。影片中採最簡易解法preorder走訪遞迴,並設參數isLeft=0,其他解法詳見Leetcode連結。Python解請進,C++提供一行解。
Related Posts Plugin for WordPress, Blogger...

熱門文章