YouChen's Blog

YouChen's Blog

rust-sync
發表於2026-05-26
Synchronization is how concurrent programs coordinate independent work. In Rust, the type system prevents many unsafe data races, but an application still needs clear rules for shared state, message passing, task wakeups, and concurrency limits. In Tokio, synchronization usually means coordinating asynchronous tasks. A task may run on the same OS thread as another task, or it may move between worker threads. Because of that, Tokio provides async-aware primitives in tokio::sync [1]. They look ...
Minimum Window Substring
發表於2026-01-27|leetcode
Minimum Window SubstringProblem DescriptionGiven two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "". The testcases will be generated such that the answer is unique. IntuitionWe need to find the shortest substring of s that contains all characters from t. Store the character frequencies of t in a hash map...
Kth Smallest Element in BST
發表於2026-01-27|leetcode
230. Kth Smallest Element in a BSTProblem DescriptionGiven 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. IntuitionBinary TreeIn BST, all nodes in the left subtree are smaller than the root. So if the left subtree has L nodes, the root is the (L+1)th smallest. We can use this to decide whether to go left, return current, or go right.inorderIn BST, an inorder traversal visits nodes in sorted order, so th...
Product of Array Except Self
發表於2026-01-27|leetcode
Product of Array Except SelfProblem DescriptionGiven an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. You must write an algorithm that runs in $O(n)$ time and without using the division operation. IntuitionSince product[i] should be the product of all numbers except nums[i], we could break it down into two parts left[i] and ...
Lowest Common Ancestor of BST
發表於2026-01-27|leetcode
Lowest Common Ancestor of a Binary Search TreeProblem DescriptionGiven 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).” IntuitionSince tree is BST, we know every left child is strictly less than root value, and eve...
Validate Binary Search Tree
發表於2026-01-27|leetcode
Validate Binary Search TreeProblem DescriptionGiven 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 strictly less than the node’s key. The right subtree of a node contains only nodes with keys strictly greater than the node’s key. Both the left and right subtrees must also be binary search trees. IntuitionBased on the BST definition, we could set min and max as the val...
3sum
發表於2026-01-27|leetcode
3sumProblem DescriptionGiven an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets. IntuitionWe can break down this problem by fixing one element and converting it into a 2Sum problem: Fix one element as the first number Solve for the remaining elements using the 2Sum approach Time Complexity: $O(n^2)$Space Complexity: $O(n)$ for s...
Binary Tree Level Order Traversal
發表於2026-01-27|leetcode
Binary Tree Level Order TraversalProblem DescriptionGiven the root of a binary tree, return the level order traversal of its nodes’ values. (i.e., from left to right, level by level). IntuitionDFSWe use layer to track current node’s depth. We insert values from top to bottom and from left to right by visiting left subtree before right subtree. BFSWe use a queue to track all nodes at the current level. For each level, we process all nodes in the queue: extract their values and add their childr...
Construct Binary Tree from Preorder and Inorder
發表於2026-01-27
105. Construct Binary Tree from Preorder and Inorder TraversalProblem DescriptionGiven 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. IntuitionThe front element of preorder traversal is the tree’s root node(the middle of inorder traversal). We use it to determine which elements belong the left subtree and the right subtree, and keep comparing the preo...
Container With Most Water
發表於2026-01-27|leetcode
Container With Most WaterProblem DescriptionYou are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the $i^{th}$ line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that you may not slant the container. IntuitionThe area of water a container is determined by two factors: heig...
12…4
avatar
YouChen Huang
不吃早餐會變笨蛋
文章
36
標籤
14
分類
3
Follow Me
公告
This is my Blog
最新文章
rust-sync2026-05-26
Minimum Window Substring2026-01-27
Kth Smallest Element in BST2026-01-27
Product of Array Except Self2026-01-27
Lowest Common Ancestor of BST2026-01-27
分類
  • backend8
  • data structures and algorithms12
  • leetcode14
標籤
csharp BST stack two_pointer dfs development tool linked_list sliding_windows rust database dynamic_programming OS Tree bfs
歸檔
  • 五月 2026 1
  • 一月 2026 10
  • 十月 2025 16
  • 九月 2025 6
  • 八月 2025 1
  • 十月 2024 2
網站資訊
文章數量 :
36
訪客數 :
總瀏覽量 :
最後更新時間 :
© 2025 - 2026 By YouChen Huang框架 Hexo 7.3.0|主題 Butterfly 5.5.4