/* 自定義代碼塊樣式 */
Herr Deng桑的教學blog
這是Herr Deng桑的教學blog,主要處理作業與班導事務,另外還有數位小品。
網頁
首頁
密碼學
程式設計Programming
APP
計算機概論
herrDeng網內搜尋
自訂搜尋
Ads
顯示具有
LeetCode
標籤的文章。
顯示所有文章
顯示具有
LeetCode
標籤的文章。
顯示所有文章
2026年9月4日 星期五
0ms C++ Py3 |Suffix MIN與Prefix MAX解Leetcode 3903, 3904 Smallest Stable Index
0ms C++ Py3 Suffix MIN與Prefix MAX解Leetcode 3903, 3904 Smallest Stable Index
使用一個名為 suf 的陣列來記錄字尾最小值(suffix min)。
接著進行動態Prefix MAX(字首最大值)的計算,以找出何時滿足Max-suf[i] leq k!
[Py3 code請進]
按我讀文 »
2026年9月2日 星期三
0ms C++ 1-line Py3解Leetcode 3875, 3876 Construct Uniform Parity Array
0
ms C++ 1-line Py3解Leetcode 3875, 3876 Construct Uniform Parity Array
一次解Leetcode 3875, 3876,code很簡單,重點是邏輯。
Solving LeetCode 3875 & 3876 together. Simple code, focus is on the logic.
[code on Leetcode 3875]
https://leetcode.com/problems/construct-uniform-parity-array-i/solutions/8496231/1beats-100-by-anwendeng-o9jh/
按我讀文 »
2026年8月28日 星期五
0ms |C++貪婪mask dp解Leetcode難題3734 Lexico min Palindrome greater then target
0ms |C++貪婪mask dp解Leetcode難題3734 Lexico min Palindrome greater then target
這部影片詳細解析了 LeetCode 3734 難題。我們將結合「貪婪演算法 (Greedy)」與「位元遮罩動態規劃 (Bitmask DP)」技術,目標是找出比給定字串大、且字典序最小的回文字串。影片中展示了如何透過剪枝與狀態壓縮將效能優化至 0ms,達成最速解。適合想挑戰高難度演算法與 C++ 實作技巧的開發者。
按我讀文 »
2026年8月21日 星期五
C++ 0ms使用inclusion exclusion, bitmask DP, 二元搜尋解Leetcode難題3116 Kth Smallest Amount With Denomination
C++ 0ms使用inclusion exclusion, bitmask DP, 二元搜尋解Leetcode難題3116 Kth Smallest Amount With Denomination
[codes on Leetcode]
https://leetcode.com/problems/kth-smallest-amount-with-single-denomination-combination/solutions/8473317/reduced-coins-mask-dpbinary-searchbeats-6acqj/
這是一題難度標記為 Hard 的 LeetCode 3116 題目。本影片將深入解析如何利用 C++ 達到極致的 0ms 執行效能!我們不只是解題,更要追求最優解。
按我讀文 »
2026年8月20日 星期四
0ms Branchless Leetcode 3069 | Py3 & C++ 高速解法
Py3 CPP 速解3069 Distribute Elements Into Two Arrays I
為什麼要寫branchless code?避免 CPU 的分支預測失敗!當代CPU 會預先猜測條件判斷(如 if-else)的結果並繼續往下執行。當預測成功時,猜對了效能極佳,猜錯了會造成時間上的懲罰。利用容器index的True or False達成Branchless code!
[C++ Python3 codes請進]
按我讀文 »
2026年8月15日 星期六
0ms C++ Py3 1 line 解 Leetcode 3702 sequence With Non Zero Bitwise XOR
0ms C++ Py3 1 line 解 Leetcode 3702 sequence With Non Zero Bitwise XOR
迴圈解不稀奇,Python一行解也不稀奇,C++一行解就很少了!
[C++ Py3 一行解請進 👇]
按我讀文 »
2026年8月12日 星期三
C++ Py3|Sliding window hashmap解Leetcode 2958 Length of Longest Subarray With at Most K
Beat 99.89% C++ Py3|Sliding window hashmap解Leetcode 2958 Length of Longest Subarray With at Most K
一陣子沒出Leetcode解題長片。這題其實很標準2958. Length of Longest Subarray With at Most K Frequency,適合練習sliding window+ hash map ! 客製化的hash map似乎是overkilling
按我讀文 »
2026年8月4日 星期二
Leetcode 3731 Missing Elements:試試 bitset 與1-line Python set,0ms 擊敗 100% 使用者
0ms CPP bitset Py3 1 liner set速解Leetcode 3731 Find Missing Elements
[Py3 一行解請進]
按我讀文 »
2026年7月27日 星期一
0ms 速解Leetcode 1464 最大的乘積:別只會用 Sort!試試Py nlargest, C++ nth_element
0ms|1 line Py3 #nlargest #cpp #nth_element 速解 #Leetcode1464 最大的乘積
Python 1行解用heapq.nlargest。C++2行解用nth_element,都是linear 0ms
[C++, Py3 codes請進]
按我讀文 »
2026年7月19日 星期日
0ms 1 liner C++ 解Leetcode week content 3996西洋騎士走偶次可達
C++一行解在此請按
按我讀文 »
2026年7月2日 星期四
LeetCode 3286: 別只用 Dijkstra!0-1 BFS (deque) 才是 0ms 關鍵
0ms |C++ Py3| BFS使用deque解Leetcode 3286 Find a Safe Walk Through a Grid
了解以下幾點有助於解決最短路徑問題:
所有權重相同時,只需使用基於佇列queue的廣度優先搜尋(BFS over queue)
權重有兩種非負值(如本題所示),使用基於雙端佇列(deque)的廣度優先搜尋(BFS over deque)
權重為正值時,使用基於優先權佇列(priority queue)的廣度優先搜尋(類似Dijkstra演算法)
按我讀文 »
2026年7月1日 星期三
Beats 100%|C++ UnionFind BFS解Leetcode 2812 Find the Safest Path in a Grid
Beats 100%|C++ unionFind BFS linkedList解Leetcode 2812 Find the Safest Path in a Grid
本影片詳細講解如何結合 UnionFind與 BFS(廣度優先搜尋)來解決 LeetCode 2812. Find the Safest Path in a Grid。透過 BFS 預處理所有格子到最近小偷的距離,再利用 UnionFind 找出具有最大安全性係數的路徑,最終在 C++ 實作中達到 182ms 並擊敗 100% 的紀錄!
按我讀文 »
2026年6月27日 星期六
C++ bitset array依數字 3、13、177、31622分割解Leetcode 3020 Find the Maximum Number of Elements in Subset
C++ bitset array依數字 3、13、177、31622分割解Leetcode 3020 Find the Maximum Number of Elements in Subset
不用hashmap,另圖蹊徑才有辦法快速解答Leetcode 3020.
-----
No Hashmap—forging a new path to crush LeetCode 3020 fast.
Trick: isqrt(1e9)=31622 , 177, 13, 3
[codes on Leetcodes]
https://leetcode.com/problems/find-the-maximum-number-of-elements-in-subset/solutions/8360422/divide-nums-according-to-3-1317731622bea-5tk4/
#anwendeng
按我讀文 »
2026年6月24日 星期三
Beats 100%|C/C++矩陣冪次方解Leetcode難題3700 Number of ZigZag Arrays II
Beats 100%|C/C++矩陣冪次方解Leetcode難題3700 Number of ZigZag Arrays II
[codes on Leetcode 3700]
https://leetcode.com/problems/number-of-zigzag-arrays-ii/solutions/8354788/symmetrymatrix-exponential149ms-beats-10-9hxf/
[codes on Leetcode 3699]
https://leetcode.com/problems/number-of-zigzag-arrays-i/solutions/8352758/use-symmetryprefixdpbeats-9352-by-anwend-xcjj/
在這段影片中,我將深入解析如何使用 矩陣快速冪 (Matrix Exponentiation) 來高效解決 LeetCode 難題 3700:Number of ZigZag Arrays II。這題是 ZigZag Array 系列的進階版本,對時間複雜度有極高要求。
按我讀文 »
2026年6月22日 星期一
0ms|Leetcode1189 text中可有幾個ballon|C++ 1 liner Py3
0ms|Leetcode1189 text中可有幾個ballon|C++ 1 linerPy3
會處理count freq,接著來就能處理counting sort
[Leetcode 1833 Maximum Ice Cream Bars|Greedy counting sort]
https://www.youtube.com/watch?v=4deOmcdAekg
[codes on Leetcode]
https://leetcode.com/problems/maximum-number-of-balloons/solutions/8350164/count-freqbeats-100-by-anwendeng-be0r/
[Py3 1-liner請進]
按我讀文 »
2026年6月21日 星期日
0ms C++ Py3|Leetcode 1833 Maximum Ice Cream Bars|Greedy counting sort
counting sort 0ms cpp py3 Leetcode1833
貪婪計數排序速解Leetcode 1833 Maximum Ice Cream Bars
[codes on Leetcode]
https://leetcode.com/problems/maximum-ice-cream-bars/solutions/8348036/greedy-counting-sortbeats-100-by-anwende-x10v/
按我讀文 »
2026年6月18日 星期四
LeetCode 1344 分針時針夾角:0ms 一行秒殺 (C++/Python)
0ms| 1-liner C++ Py3|1344. Angle Between Hands of a Clock
應徵程式設計師,也會問小學數學,不用懷疑。
-----
When applying for a programmer position, they'll ask you elementary school math questions, no doubt about it.
#leetcode #1liner #cplusplus #python #leetcode1344
[Py3 1-liner請進]
按我讀文 »
2026年6月16日 星期二
C, Py3, C++解Leetcode 3612 與難題3614 Process String with Special Operations
C Py3 C++解Leetcode 3612 與難題3614 Process String with Special Operations
一個字串問題Leetcode 3612,用C++或Python是易如反掌,用C語言就難多了,然而這個解題經驗,順便用來解所謂hard 3614. Process String with Special Operations II
按我讀文 »
2026年6月12日 星期五
C++Binary Lifting 視覺化解說 Leetcode
Beats 100%|C++ BFS LCA binary lifting與模指數運算解Leetcode難題3559 Number of Ways to Assign Edge Weights II
#anwendeng
Beats 100%|C++ BFS LCA binary lfting與模指數運算解Leetcode難題3559 Number of Ways to Assign Edge Weights II
- Adjacency-list: array linked Lists
- BFS - construct parent[], level[]
- LCA- binary lifting - distance
- Fast modular power , pow2
- query call distance & pow2 to give answer
按我讀文 »
較舊的文章
首頁
訂閱:
文章 (Atom)
熱門文章
array
array ex 1, 2,3,7,8
統計2
統計第一作業 2, 3, 8, 9
簡易程式1
請問如何用C/C++程式產生下列輸出? 1111111 2222222 3333333 4444444 5555555 6666666 7777777
C字串練習
C字串練習 字串 char word[]="You win!"; 輸出為: You win! You win You wi You w You You Yo Y 給進階使用者: gets () 是個危險的函式!
ex3 請用CPU-Z軟體檢測Cache & Memory
請用CPU-Z軟體檢測Cache & Memory 註:快取(L1-L3: SRAM) 第一級快取(L1)–通常存取只需要幾個週期,通常是幾十個KB。 第二級快取(L2)–比L1約有2到10倍較高延遲性,通常是幾百個KB或更多。 第三級快取(L3)(不...
GCD
GCD(123456789,345634567)=?
無線網路中WEP安全嗎?
Ex1 撰寫C++程式與Dev C++設定
Vigenere加密
明文=I'm student key=(2,15,8) 密文=?
作業 3
請輸出如下 * ** *** **** ***** ******