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

herrDeng網內搜尋

自訂搜尋

Ads

2025年12月8日 星期一

Py3 C++利用Euclid公式達O(n)解Leetcode1925 Count Square Sum Triples


Py3 C++利用Euclid公式達O(n)解Leetcode 1925  Count Square Sum Triples
用數論方法解畢氏定理三角整數解個數,這應該算是Diophantine  Equation中最簡單的例題
[Py3解請進]

2025年12月2日 星期二

Py3 C++ hashmap多項次公式解梯形問題Leetcode 3623 Count Number of Trapezoids I


Py3 CPP多項次公式解梯形問題Leetcode 3623  Count Number of Trapezoids I
數有幾個不同水平梯形,先用hash map數有相同y座標的點,再用多項次公式解題
[Py3解請進]

2025年11月27日 星期四

2025年11月25日 星期二

Py3 C++找出pattern迭代變化解出Leetcode 1015 Smallest Integer Divisible by K


所謂的數論問題,也不一定是是像費馬定理那樣的大問題,能找出數字間的pattern也都是值得玩味的
執行直到 r=(10*r+1)%k==0(其中 k 與 2 和 5 互質),否則返回 -1
[Py3 code請進]

2025年11月16日 星期日

C++用 -1 mask法達到branchless解Leetcode1513 Number of Substrings With Only 1...


C++用 -1 mask法達到branchless解Leetcode1513  Number of Substrings With Only 1s|Py3 1-liner
其實很容易,想練功,試試一行解,或是把if分岔拿掉
[C++無分岔解請進]

2025年11月14日 星期五

Py3 C++ 2D sweep解Leetcode 2536 Increment Submatrices by One


Py3 C++ 2D sweep解Leetcode 2536  Increment Submatrices by One
使用2D掃描,方法為line sweep的2D推廣,方便好用。
[Py3解請進]
Related Posts Plugin for WordPress, Blogger...

熱門文章