一、學習目標 正確判斷 Dijkstra 的適用條件:邊權 ≥ 0。 熟練最小堆(priority_queue with greater) 的寫法與「鬆弛(r...
一、學習目標 把不同型態的 DP(計數型、最佳化型、線性 DP、環狀 DP、字串 DP)串起來。 熟練「狀態定義 → 轉移 → 初始條件 → 答案位置」的完整...
一、學習目標 分辨何時用 貪心(依結束時間排序)、何時用 DP(帶權區間排程)。 熟悉帶權區間 DP:排序、預處理 prev(相容區間)、二分查找轉移。 能將...
一、學習目標 了解以 bitmask 表示子集合與其時間/空間複雜度 掌握 dp[mask](或 dp[mask][i])的狀態設計與轉移。 熟悉 子集合枚舉...
一、學習目標 把題目抽象成 dp[l][r]:表示處理區間 [l..r] 的最佳值/最少代價。 會寫兩大形態的轉移: 兩端取數:dp[l][r] 來自 dp...
一、學習目標 會定義 LIS(Longest Increasing Subsequence) 與「嚴格遞增 vs 非嚴格遞增」的差異。 熟練兩種做法: O(...
一、學習目標 理解兩大類背包:0/1(每件最多一次)vs 完全(可重複拿)。 會寫出正確的雙迴圈順序,避免重複/漏算: 0/1:容量倒序。 完全:容量正序。...
一、學習目標 會把問題抽象成:狀態、轉移、初始值、答案位置、迭代順序(五步驟)。 熟悉一維 DP 的兩大類: 計數型(有幾種方法):例 Dice、Climb...
一、學習目標 熟悉多源 BFS(多個起點同時擴散)與單源 BFS 的配合:先以多源 BFS 建出「危險/時間場」,再用單源 BFS 找可行最短路。 了解「BF...
一、學習目標 了解 DFS 的兩種實作:遞迴與疊代(顯式 stack),何時該避免遞迴以防止棧爆。 掌握三個核心觀念:visited 標記、連通塊(conne...
桶子排序是什麼? 桶子排序是一種 把資料分類再逐一排序 的演算法。想像一下你有一堆數字,目標是從小到大排列,但這堆數字範圍很大、分布也不均勻。 因此桶子排序的想...
卡爾曼濾波器例子:追蹤汽車的位置與速度 第一步:預測(依據運動規律) 運動規律 假設汽車的運動規律如下: 位置變化: 每秒的「位置」 = 前一秒的位置 +...
Collision When two or more objects happen to be hashed into the same index in th...
The big O of finding an element with sequential search method in a traditional a...
首先,必須先給成功完成連續30天發鐵人賽文章的自己來一點很大的掌聲嗚嗚嗚嗚!!!OK,我們來回顧一下這30天都寫了些什麼、做了些什麼努力吧! 在這30天中,我們...
原文題目 Given an integer array nums, find the subarray with the largest sum, and re...
原文題目 Given an integer array nums, return an array answer such that answer[i] is...
原文題目 Given an array nums of size n, return the majority element. The majority el...
原文題目 A trie (pronounced as "try") or prefix tree is a tree data struct...
字典樹(Trie) 是一種專門用來處理字串(單字)的樹狀結構,特別適合解決字串(單字)集合中的「前綴匹配」問題。它的每個節點代表一個字母,並且從根節點到某個葉節...
原文題目 Write an efficient algorithm that searches for a value target in an m x n i...
原文題目 Given an m x n integer matrix matrix, if an element is 0, set its entire ro...
原文題目 You are given an n x n 2D matrix representing an image, rotate the image by...
矩陣(Matrix) 與基本的陣列結構息息相關,有點類似於二維陣列,它是一個利用mxn的陣列來介紹矩陣擁有m列和n行。而一般資料結構與演算法上常用到的矩陣有四種...
最近兩個主題我們談到了「堆疊 (Stack)」和「堆積 (Heap)」,即使它們在中文上只有一字之差,但在電腦科學中,它們的用途和特性是非常不同的。 1. 堆疊...
原文題目 Given an array of integers temperatures represents the daily temperatures,...
原文題目 Given an encoded string, return its decoded string. The encoding rule is: k...
原文題目 Design a stack that supports push, pop, top, and retrieving the minimum ele...
堆疊演算法(Stack) 是一種有序串列(即一群相同資料型態的組合),具有「後進先出」(Last In First Out, LIFO)的特性,故其所有的動作、...
原文題目 Given an integer array nums and an integer k, return the k most frequent el...