↓快轉到主要內容

Simulation

LeetCode 3775: Reverse Words With Same Vowel Count
·1 分鐘
LeetCode Medium String Simulation Two-Pointers
LeetCode 3775 解題筆記:先數第一個字的母音數,後面母音數一樣的字就反轉
LeetCode 2105: Watering Plants II
·1 分鐘
LeetCode Medium Two-Pointers Simulation Array
LeetCode 2105 解題筆記:Alice 從左、Bob 從右,對撞指針模擬澆水;相遇在同一株時由水比較多的人澆
LeetCode 3813: Vowel-Consonant Score
·1 分鐘
LeetCode Easy String Simulation
LeetCode 3813 解題筆記:只數字母,分成母音和子音;子音是 0 時分數是 0,否則用整數除法
LeetCode 3679: Minimum Discards to Balance Inventory
·1 分鐘
LeetCode Medium Sliding-Window Hash-Table Simulation Counting Array
LeetCode 3679 解題筆記:規則已經決定哪些要丟,直接模擬;長度 w 的視窗只計算「留下來」的到貨,被丟掉的離開視窗時不能再扣
LeetCode 3703: Remove K-Balanced Substrings
·2 分鐘
LeetCode Medium Stack String Simulation
LeetCode 3703 解題筆記:反覆 replace 是 O(n^2);stack 存 (字元, 連續個數),湊到 k 個 ( 加 k 個 ) 就整段消掉
LeetCode 3701: Compute Alternating Sum
·1 分鐘
LeetCode Easy Array Simulation
LeetCode 3701 解題筆記:偶數 index 加、奇數 index 減;用切片就是 sum(nums[::2]) - sum(nums[1::2])
LeetCode 3688: Bitwise OR of Even Numbers in an Array
·1 分鐘
LeetCode Easy Bit-Manipulation Array Simulation
LeetCode 3688 解題筆記:只對偶數做 OR;初始值 0 剛好也是「沒有偶數」時的答案
LeetCode 853: Car Fleet
·1 分鐘
LeetCode Daily Medium Array Stack Greedy Simulation Sorting
使用堆疊方法解決車隊問題
LeetCode 1222: Queens That Can Attack the King
·1 分鐘
LeetCode Medium Array Matrix Simulation
LeetCode 1222 解題筆記:從國王往八個方向一步一步走,每個方向第一個遇到的皇后就能攻擊;皇后放進集合方便查詢
LeetCode 2402: Meeting Rooms III
·2 分鐘
LeetCode Hard Heap Sorting Simulation Intervals
LeetCode 2402 解題筆記:空閒房間和忙碌房間各一個 heap,延後的會議要保留原本的長度
LeetCode 3612: Process String with Special Operations I
·1 分鐘
LeetCode Medium String Simulation
LeetCode 3612 解題筆記:用 list 模擬四種操作;判斷 * 時要把「結果非空」寫在分支裡面,不然 * 會被當成字母加進去
LeetCode 1920: Build Array from Permutation
·1 分鐘
LeetCode Easy Array Simulation
LeetCode 1920 解題筆記:照定義 ans[i] = nums[nums[i]];要 O(1) 額外空間時,把新值乘 n 疊在原本的值上