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

herrDeng網內搜尋

自訂搜尋

Ads

顯示具有 程式設計[視訊] 標籤的文章。 顯示所有文章
顯示具有 程式設計[視訊] 標籤的文章。 顯示所有文章

2026年4月21日 星期二

C++UnionFind與陣列版Linked list解Leetcode 1722 Minimize Hamming Distance After Swap Operations


C++UnionFind與陣列版Linked list解Leetcode 1722  Minimize Hamming Distance After Swap Operations
真正的C++硬和解答,用 Union-Find解答Leetcode 1722. Minimize Hamming Distance After Swap Operations, 用兩個靜態陣列實作Linked  List取代2D  vector或是hash map
只要幾ms就run完了所有的testcases,當然是100% 
-----
A true C++ hard-solution solution, using Union-Find to solve Leetcode 1722. Minimize Hamming Distance After Swap Operations, implementing a Linked List using two static arrays instead of a 2D vector or hash map. All test cases run in just a few milliseconds, achieving 100% completion.
[C++ UnionFind BFS DFS解圖論問題Leetcode 1971 Find if Path Exists in Graph]https://www.youtube.com/watch?v=B1GQlUN08lk

2026年4月12日 星期日

Py3 C++ DP速解1320 Minimum Distance to Type a Word Using Two Fingers


Py3 C++ DP速解1320  Minimum Distance to Type a Word Using Two Fingers
這題確實有難度,最初的解答是3D DP,然後逐次化簡,化成2D後,大該就已經是極致了,不想用hash map,300x (26+1)也不大,0ms C++ code
-----
This problem is indeed challenging. The initial solution was 3D dynamic programming, which was then simplified to 2D, reaching its limit. I didn't want to use a hash map; 300x (26+1) isn't a large number. 0ms C++ code.

2026年4月6日 星期一

C++ unordered set PMR解Leetcode 874 Walking Robot Simulation


C++ unordered set PMR解Leetcode 874  Walking Robot Simulation
解Leetcode 874. Walking Robot Simulation因為constraints,只好用hashmap,C++ unordered_set是知名的慢,加上pmr可以快上幾倍 
------
Solving LeetCode 874, Walking Robot Simulation, requires using a hashmap due to constraints. C++'s unordered_set is notoriously slow; adding PMR can speed it up several times.

2026年3月28日 星期六

C++UnionFind與matrix分析解難題Leetcode 2573 Find the String with LCP


解難題Leetcode 2573. Find the String with LCP,其實重點是lcp非常特殊的矩陣,只要搞定lcp各項的關聯,如對稱性,對角線上值-1等特性,應該能解出。會先用Union-Find主要是其解法可針對更為廣義的題目,要快就用貪婪。

2026年2月28日 星期六

Py3 C++位元處理與DP解Leetcode 1680 Concatenation of Consecutive Binary Numbers


Py3 C++位元處理與DP解Leetcode 1680  Concatenation of Consecutive Binary Numbers
這當然不是DP的問題,但透過DP的手法卻可以大幅減少計算時間
----
This is certainly not a problem with dynamic programming (DP), but by using DP techniques, the computation time can be significantly reduced.

2026年2月21日 星期六

C++ Py3 bitmask速解Leetcode 762 Prime Number of Set Bits in Binary Representation


C++ Py3 bitmask速解Leetcode 762  Prime Number of Set Bits in Binary Representation
這段影片示範如何使用計數位元和位元遮罩(bit mask),用幾行程式碼解決這個問題。
-----
this video shows how to use count bits & bitmask to solve this question in few lines. 

2026年2月19日 星期四

Py3 C++迴圈與計數解Leetcode 696 Count Binary Substrings


Py3 C++迴圈與計數解Leetcode 696  Count Binary Substrings
Leetcode 696. Count Binary Substrings雖然標示為easy,也沒那麼trivial,花了一番功夫才解出branchless C++。而一般回圈解倒是不難,但須要思考一下
-----
Leetcode 696. Count Binary Substrings, though marked as easy, isn't exactly trivial; it took me some effort to solve it in branchless C++. Solving the general loop problem isn't difficult, but it needs thinking.

2026年2月13日 星期五

Py3 C++使用 4 hashmaps解Leetcode 3714 Longest Balanced Substring II

 
 不喜歡C++的unordered_map,主要的原因是慢,也不想重新刻一個好的hashmap,不過透過memory_resource中的工具,加快三倍速度,也能寫出簡易的beats 99%C++解答

2026年2月4日 星期三

py3 C++巢狀迴圈解Leetcode難題3640 Trionic Array II


py3 CPP巢狀迴圈解Leetcode難題3640  Trionic Array II
使用巢狀迴圈來解決 LeetCode 上的難題,就用類似解決簡單的題目的方法。
Lettcode 3637. Trionic Array I簡單問題解了,困難的類似題3640. Trionic Array II也用類似方法解了。不要小看怎麼用迴圈

2026年2月1日 星期日

C++ Py3用nth_element, nsmallest解Leetcode 3010 Divide an Array Into Subar...


C++ Py3用nth_element, nsmallest解Leetcode 3010  Divide an Array Into Subarrays With Minimum Cost I
問題簡單,但應該是同類問題入門,先提供幾個簡易解答
[Py3一行解請進]
----

2026年1月24日 星期六

計數排序與greedy 2 pointer解Leetcode 1877 Minimize Maximum Pair Sum in Array


計數排序與greedy 2 pointer解Leetcode 1877  Minimize Maximum Pair Sum in Array 重點是理解為何Greedy方法可行,code很簡單,就排序sort, counting sort, radix sort都來一遍
[Py3 一行解請進]

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請進]
Related Posts Plugin for WordPress, Blogger...

熱門文章