herrDeng網內搜尋

自訂搜尋

Ads

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++提供一行解。

2024年4月12日 星期五

python c++用monotonic stack解 Leetcode難題42 trapping rain water並附pyplot繪直方圖解說


Python c++用monotonic stack解 Leetcode難題42 trapping rain water並附pyplot繪直方圖解說
想法是使用索引 m 的單調堆疊來找到右牆height[r]和左牆height [l];計算此區域高於底部 height[m]的水量應為min(height[r]-height[m], height[l]-height[m])*(r-l-1) 

2024年4月9日 星期二

Python C++速解Leetcode 2073 Time Needed to Buy Tickets


Python CPP速解LLeetcode 2073  Time Needed to Buy Tickets
假設x=tickets[k]。 當i≤k時,person[i]最多只能買x張票; 當 i大於k時,person[i]最多只能購買 x-1 票。python code請進

2024年4月7日 星期日

python C++DP動態規劃解Leetcode 678 Valid Parenthesis String


python C++DP動態規劃解Leetcode 678  Valid Parenthesis String
使用2D DP來求解。 由於 n≤100,因此帶有 memo 的遞迴可以完成這項工作。 知道了遞迴那麼DP就一定可行!
第二種方法是迭代 DP 程式碼; 使用 &1 技巧減少空間至O(n)。Python code請進 。

2024年4月6日 星期六

python C++字串deque解Leetcode 1249 Minimum Remove to Make Valid Parentheses


python C++字串deque解Leetcode 1249  Minimum Remove to Make Valid Parentheses
連續幾天都是含括號的字串問題Leetcode 1249. Minimum Remove to Make Valid Parentheses,都提示用stack其實不用,走訪兩次就好,一次去掉多的 ')' ,第二反向去掉多的 '(' ;選用適當的容器,字串、deque就得解了,最快的C++解請進

2024年4月5日 星期五

python C++速解Leetcode 1544 make the string great


python C++速解Leetcode 1544 make  the string great
基本上算是stack解法,但實作的語言C, C++, python只需要善用個別字串的特性,無須使用stack,大幅加快計算速度,C語言解答請進,並加上最佳C++解
Related Posts Plugin for WordPress, Blogger...

熱門文章