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

herrDeng網內搜尋

自訂搜尋

Ads

2025年9月16日 星期二

C C++ GCD LCM解Leetcode難題2197 Replace Non Coprime Numbers in Array[含Py3 code]


C C++ GCD LCM解Leetcode難題2197  Replace Non Coprime Numbers in Array
用binary Euclidean algorithm定義gcd,然後定義lcm之後就是用stack
[Py3 code請進]

2025年9月14日 星期日

C++ Trie prefix tree解母音拼字Leetcode 966 Vowel Spellchecker


C++ Trie  prefix tree解母音拼字Leetcode 966  Vowel Spellchecker
如果unordered_set, unordered_map有其他替方案就用,能用Trie去解也算是一種成就
 --------
If there are alternatives to unordered_set and unordered_map, use them. Being able to solve them with Trie is also an achievement.

2025年9月10日 星期三

C++示範bitset取代hashset解Leetcode 1733 Minimum Number of People to Teach(含Py3 code)


C++示範bitset取代hashset解Leetcode 1733  Minimum Number of People to Teach
C++ STL的unordered_set與bitset都能解這題,但執行效率差很多,有誰寫C++其執行效能要比類似的Python code還要慢上好久倍?用hashset就如此
[Python code請進 ]

2025年9月6日 星期六

C++C py3 log4 prefix sum, bits解Leetcode難題3495 Minimum Operations to Mak...


C++C py3 log4 prefix sum/bits解Leetcode難題3495  Minimum Operations to Make Array Elements Zero
ceil(log4(x)) 可以透過 clz 計算;將 expSum 定義為部分和來計算。
[Py3 code請進]

2025年8月31日 星期日

C++回遡與bitmask解Leetcode 37數獨Sudoku


C++回遡與bitmask解Leetcode 37數獨Sudoku
有些經典問題值得一解再解,雖然不是最佳解,也要比Leetcode Editorial的解有效許多。解數獨,回遡乃基本款,但加上bitmask就能篩掉許多無用的測試,就更快許多
-----
Some classic problems are worth solving again and again. Although they are not the best solutions, they are much more effective than Leetcode Editorial's solutions. Solve Sudoku by using backtracking is the basic version, but add bitmask to filter out many useless tests can make it much faster.
[其他採回溯未用bitmask解法]https://www.youtube.com/watch?v=wviWrbbOdYE

2025年8月28日 星期四

Py3 C++速解Leetcode 3446 Sort Matrix by Diagonals/with Py3 code


Py3 C++速解Leetcode 3446  Sort Matrix by Diagonals
矩陣問題都是很好的迴圈、陣列練習,又加上排序那就是很好的練習題
[Py3 code請進]
Related Posts Plugin for WordPress, Blogger...

熱門文章