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

herrDeng網內搜尋

自訂搜尋

Ads

顯示具有 LeetCode 標籤的文章。 顯示所有文章
顯示具有 LeetCode 標籤的文章。 顯示所有文章

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月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請進]

2025年8月27日 星期三

C++ dp動態規劃解Leetcode 3459 Length of Longest V Shaped Diagonal Segment


C++ dp動態規劃解Leetcode 3459  Length of Longest V Shaped Diagonal Segment
採DP動態規劃迭代版本解難題,需要定義V-shaped distance
------
Using the DP dynamic programming iterative version, it is necessary to define the V-shaped distance

2025年8月24日 星期日

Py3 C++ sliding window速解Leetcode1493 Longest Subarray of 1's After Dele...


Py3 C++ sliding window速解Leetcode1493  Longest Subarray of 1's After Deleting One Element
示範如何從一般  sliding window解答簡化成單迴圈解答解無if
[Py3解在此,請進]

2025年8月16日 星期六

Py3 C++陣列迴圈速解Leetcode 1323 Maximum 69 Number


Py3 C++陣列迴圈速解Leetcode 1323  Maximum 69 Number
學程式的第一式,就是要會活用陣列迴圈,足以解Leetcode 1323. Maximum 69 Number 
[Py3解請進]

2025年8月13日 星期三

C++一行解Leetcode 326 Power of Three


C++一行解Leetcode 326  Power of Three
利用3的羃次方的因數也是3的羃次方,導出一行C++程式碼
[解答請進]

2025年8月5日 星期二

segment tree C++解Leetcode 3479 Fruits Into Baskets III


segment tree C++解Leetcode 3479  Fruits Into Baskets III
線段樹(segment tree)是一種進階的資料結構,可以用來解決一些 LeetCode 難題。
線段樹本質上是一棵二元樹;它可以用二元樹來實現,但更常見的是使用陣列表示。這題需要用到有最大值的線段樹;以及一種尋找第一個不小於target的basket然後更新的方法。
------
Segment tree is an advance data struture which can solve several Leetcode questions.
Segment tree is basically a binary tree, ; it can be implemented by using binary tree, but most frequently its array representation way. This question needs the segment tree with max; and a method which  searchs the 1st basket not less than target & then updates it.

2025年8月3日 星期日

2025年7月16日 星期三

Py3 C++奇偶交錯奇偶子數列解Leecode 3201 Find the Maximum Length of Valid Subsequ...


Py3  C++奇偶交錯奇偶子數列解Leecode 3201  Find the Maximum Length of Valid Subsequence I
求最長有效子序列,使得 (sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2,有 3 種可能的情況
-全為偶數
-全為奇數
-或奇偶交錯子序列
[Py3解請進]

2025年7月15日 星期二

Py3 C++母音 vowel mask速解Leetcode 3136 Valid Word

Py3 C++母音 vowel mask速解Leetcode 3136  Valid Word
Leetcode有許多判斷母音的問題,採用bitmask方式,迅速又方便
-----
Leetcode has many problems in determining vowels. Using the bitmask method is fast and convenient.
Related Posts Plugin for WordPress, Blogger...

熱門文章