CDCHAO DUinleetlog-by-chao.hashnode.dev·Dec 3, 2025 · 3 min readLeetCode 494. Target Sum — 0/1 Knapsack ReframedThis post solves LeetCode 494. Target Sum by converting it into a subset sum / 0-1 knapsack counting problem. Problem Summary You are given an array nums and a target.By placing '+' or '-' in front of each number, you create an expression such as: +...00
CDCHAO DUinleetlog-by-chao.hashnode.dev·Dec 2, 2025 · 3 min readLeetCode 1049 – Last Stone Weight II1. Problem Overview We are given an array stones[i] representing weights. Each turn: Pick two stones x ≤ y if x == y: both vanish else: new stone = y - x At most one stone remains.Return the smallest possible final weight. Example: Input: [2,7,...00
CDCHAO DUinchaodu.hashnode.dev·Dec 1, 2025 · 4 min readLeetCode 416 — Partition Equal Subset Sum (My Debug Log)This problem looks simple at first, but it actually teaches you one of the most important dynamic programming patterns:subset sum = 0/1 knapsack. Here is my complete debug journey: from wrong brute force → wrong greedy → correct DP. 1. First Attempt...00
CDCHAO DUinleetlog-by-chao.hashnode.dev·Nov 28, 2025 · 6 min readUnique Binary Search Trees (LeetCode 96): A Complete ExplanationThis article explains the correct dynamic programming solution for LeetCode 96: Unique Binary Search Trees.I also document a common mistake that many learners make, including myself: trying to derive dp[n] by inserting a new node into all BSTs of siz...00
CDCHAO DUinleetlog-by-chao.hashnode.dev·Nov 28, 2025 · 4 min readLeetCode Daily Log — Integer Breakhttps://leetcode.cn/problems/integer-break/ Date: 2025-11-28Difficulty: MediumTopics: Dynamic Programming, MathStatus: Solved 1. Problem Summary Given an integer n, split it into at least two positive integers such that the product of these integers...00