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

herrDeng網內搜尋

自訂搜尋

Ads

2024年9月3日 星期二

python C++速解Leetcode 1945 Sum of Digits of String After Convert


python C++速解Leetcode 1945  Sum of Digits of String After Convert
這是個簡單問題,有技巧。
第一次轉換不需要用bigINT來存,只是將數字與第1輪的數字相加即可。
由於s.length最多可能為100,因此使用bigInt或其他字串效率非常低。
[Python code請進]
---

2024年8月23日 星期五

C++ stringstream解分數加減Leetcode 592 Fraction Addition and Subtraction


C++ stringstream解分數加減Leetcode 592  Fraction Addition and Subtraction
程式設計分數加減很難嗎?計算容易,但處理字串費事,用stringstream就簡單了

2024年8月17日 星期六

C++ DP動態規劃解Leetcode 937 Maximum Number of Points with Cost


C++ DP動態規劃解Leetcode 937  Maximum Number of Points with Cost
有些標示medium要比標示hard的問題還要難,Leetcode 1937. Maximum Number of Points with Cost,DP動態規劃可解,但怎麼樣的遞迴關係才能降低時間複雜度?
[Python解請進]
----------

2024年8月15日 星期四

python C++ Greedy速解找零問題Leetcode 860 Lemonade Change


python C++ Greedy速解找零問題Leetcode 860  Lemonade Change
b=20時貪婪演算法保持檢查順序,先找十塊,不要改變檢查順序,否則不起作用
[python解請進]
-----

2024年8月10日 星期六

2024年8月9日 星期五

Python C++解魔方陣Leetcode 840 Magic Squares In Grid



Python C++解魔方陣Leetcode 840  Magic Squares In Grid.
影片一開始就是展示如何解一個3x3的魔方陣,5總是在中心
In the beginning of film is to show how to solve a 3x3 magic square, 5 is always in the center.

2024年8月2日 星期五

Python C++ sliding windows解Leetcode 2134 Minimum Swaps to Group All 1'...


Python C++  sliding windows解Leetcode 2134  Minimum Swaps to Group All 1's Together II
使用sliding window, 由於陣列是循環的,所以右邊的游標r應該一直走到n+n0或n+n1
[Python  code請進]
-----

2024年7月26日 星期五

C++Floyd Warshall解Leetcode 1334 Find the City With the Smallest Number ...


C++Floyd Warshall解Leetcode 1334  Find the City With the Smallest Number of Neighbors at a Threshold
由於每對 (i, j) 都有許多最短路徑需要計算,採用 Floyd-Warshall 演算法比較划算。
---

2024年7月24日 星期三

Python C++速解排序問題Leetcode 2191 Sort the Jumbled Numbers


今日Leetcode的排序問題2191. Sort the Jumbled Numbers,主要有兩個部份,一個是把數字轉成另一個數字,用int就行,採Least Significant Digit First。然後排序,不建議用自訂Lambda,跑能過但非常慢;更不建議自製車輪去排序。比較快的方式是sort ((mapping(x), index),然後再從排序後的資料中取得 x
[Python code請進]

2024年7月20日 星期六

Python C++採Greedy 2 pointers解Leetcode 1605 Find Valid Matrix Given Row ...


Python CPP採Greedy 2pointers解Leetcode 1605  Find Valid Matrix Given Row and Column Sums
將大小為 r*c 的陣列 arr 初始化為全 0
獨立的 i、j 是 2 個指標。使用迴圈繼續
設 x=min(rowSum[i], colSum[j])
設定 arr[i][j]=x & rowSum[i]-=x, colSum[j]-=x 根據 rowSum[i]==0 & colSum[j]==0 移動 i, j。
[Python解請進]
----
Related Posts Plugin for WordPress, Blogger...

熱門文章