演算法

演算法的中文教學與題目實作,84 篇。每篇都會交代時間與空間複雜度怎麼算出來的,而不只給一個 O(n)。想從頭建立觀念,建議搭配資料結構標籤一起看。

快取策略完整解析封面圖:Cache-Aside、Write-Through、Write-Behind 與快取雪崩、穿透、擊穿的對應解法

快取策略完整解析:Cache-Aside、Write-Through 與快取雪崩的 10 個關鍵決策(系統設計 13)

快取策略怎麼選?本文拆解 Cache-Aside、Read-Through、Write-Through、Write-Behind、Write-Around 五種讀寫模式,六種淘汰演算法,以及快取雪崩、穿透、擊穿的成因與解法,附選型決策樹。

快取策略完整解析:Cache-Aside、Write-Through 與快取雪崩的 10 個關鍵決策(系統設計 13) Read More »

技術文章, 系統設計, ,
LeetCode 刷題策略示意圖|2026 AI 時代面試準備

如何在 AI 時代刷 LeetCode?2026 面試終極指南

如何在 AI 時代刷 LeetCode?2026 面試終極指南教你避開題海陷阱,專注高效準備。結合 AI 工具與傳統算法,成為面試真正贏家。現在開始。

如何在 AI 時代刷 LeetCode?2026 面試終極指南 Read More »

技術文章, , , , ,
Implement Trie II 解題教學示意圖|LeetCode 1804

Implement Trie II 解題教學:3 種解法完整比較|LeetCode 1804 Best Practice

A trie (pronounced as “try”) or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.

Implement the Trie class:

Trie() Initializes the trie object.
void insert(String word) Inserts the string word into the trie.
int countWordsEqualTo(String word) Returns the number of instances of the string word in the trie.
int countWordsStartingWith(String prefix) Returns the number of strings in the trie that have the string prefix as a prefix.
void erase(String word) Erases the string word from the trie.

Implement Trie II 解題教學:3 種解法完整比較|LeetCode 1804 Best Practice Read More »

Leetcode, 技術文章, , , ,
Design Add and Search Words Data Structure 解題教學示意圖|LeetCode 211

Design Add and Search Words Data Structure 解題教學:3 種解法完整比較|LeetCode 211 Best Practice

Design a data structure that supports adding new words and finding if a string matches any previously added string.

Implement the WordDictionary class:

WordDictionary() Initializes the object.
void addWord(word) Adds word to the data structure, it can be matched later.
bool search(word) Returns true if there is any string in the data structure that matches word or false otherwise. word may contain dots ‘.’ where dots can be matched with any letter.

Design Add and Search Words Data Structure 解題教學:3 種解法完整比較|LeetCode 211 Best Practice Read More »

Leetcode, 技術文章, , , ,
Implement Trie 解題教學示意圖|LeetCode 208

Implement Trie 解題教學:3 種解法完整比較|LeetCode 208 Best Practice

A trie (pronounced as “try”) or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.

Implement the Trie class:

Trie() Initializes the trie object.
void insert(String word) Inserts the string word into the trie.
boolean search(String word) Returns true if the string word is in the trie (i.e., was inserted before), and false otherwise.
boolean startsWith(String prefix) Returns true if there is a previously inserted string word that has the prefix prefix, and false otherwise.

Implement Trie 解題教學:3 種解法完整比較|LeetCode 208 Best Practice Read More »

技術文章, Leetcode, , , ,
Lowest Common Ancestor of a Binary Search Tree 解題教學示意圖|LeetCode 235

Lowest Common Ancestor of a Binary Search Tree 解題教學:3 種解法完整比較|LeetCode 235 Best Practice

Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.

According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”

Lowest Common Ancestor of a Binary Search Tree 解題教學:3 種解法完整比較|LeetCode 235 Best Practice Read More »

Leetcode, 技術文章, , , ,
Kth Smallest Element in a BST 解題教學示意圖|LeetCode 230

Kth Smallest Element in a BST 解題教學:3 種解法完整比較|LeetCode 230 Best Practice

Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.

Kth Smallest Element in a BST 解題教學:3 種解法完整比較|LeetCode 230 Best Practice Read More »

Leetcode, 技術文章, , , , ,
Validate Binary Search Tree 解題教學示意圖|LeetCode 98

Validate Binary Search Tree 解題教學:3 種解法完整比較|LeetCode 98 Best Practice

Given the root of a binary tree, determine if it is a valid binary search tree (BST).

A valid BST is defined as follows:

The left subtree of a node contains only nodes with keys less than the node’s key.
The right subtree of a node contains only nodes with keys greater than the node’s key.
Both the left and right subtrees must also be binary search trees.

Validate Binary Search Tree 解題教學:3 種解法完整比較|LeetCode 98 Best Practice Read More »

Leetcode, 技術文章, , , ,
Construct Binary Tree from Preorder 解題教學示意圖|LeetCode 105

Construct Binary Tree from Preorder 解題教學:3 種解法完整比較|LeetCode 105 Best Practice

Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree.

Construct Binary Tree from Preorder 解題教學:3 種解法完整比較|LeetCode 105 Best Practice Read More »

Leetcode, 技術文章, , , ,