Blind 75 vs NeetCode 150:Leetcode 刷題順序怎麼選?
Leetcode 刷題順序選擇困難?詳細對比 Blind 75 和 NeetCode 150 的特色與適用對象。Get started 準備面試。
Blind 75 vs NeetCode 150:Leetcode 刷題順序怎麼選? Read More »
技術文章資料結構的中文教學與實際應用,33 篇。重點不只是「它長什麼樣」,而是「什麼時候該選它」——每種結構的操作複雜度與適用情境都會講清楚。
Leetcode 刷題順序選擇困難?詳細對比 Blind 75 和 NeetCode 150 的特色與適用對象。Get started 準備面試。
Blind 75 vs NeetCode 150:Leetcode 刷題順序怎麼選? Read More »
技術文章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 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, 技術文章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 »
技術文章, LeetcodeGiven 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, 技術文章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, 技術文章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, 技術文章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, 技術文章Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.
A subtree of a binary tree tree is a tree that consists of a node in tree and all of this node’s descendants. The tree tree could also be considered as a subtree of itself.
Subtree of Another Tree 解題教學:3 種解法完整比較|LeetCode 572 Best Practice Read More »
Leetcode, 技術文章Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.
Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.
Clarification: The input/output format is the same as how LeetCode serializes a binary tree. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.
Serialize and Deserialize Binary Tree 解題教學:3 種解法完整比較|LeetCode 297 Best Practice Read More »
Leetcode, 技術文章