Leetcode

LeetCode 解題教學總覽,目前收錄 82 題。每一篇的結構都一樣:解題思路(講為什麼這樣想)、演算法步驟、複雜度分析、邊界情況與常見錯誤,最後是 3 種解法的比較表。想依題型練習(陣列、雜湊表、動態規劃、圖論⋯⋯)可以從「如何在 AI 時代刷 LeetCode」那篇的題型索引進去。

Binary Tree Maximum Path Sum 解題教學示意圖|LeetCode 124

Binary Tree Maximum Path Sum 解題教學:3 種解法完整比較|LeetCode 124 Best Practice

A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root.

The path sum of a path is the sum of the node’s values in the path.

Given the root of a binary tree, return the maximum path sum of any non-empty path.

Binary Tree Maximum Path Sum 解題教學:3 種解法完整比較|LeetCode 124 Best Practice Read More »

Leetcode, 技術文章, , , ,
Flip Equivalent Binary Trees 解題教學示意圖|LeetCode 951

Flip Equivalent Binary Trees 解題教學:3 種解法完整比較|LeetCode 951 Best Practice

For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees.

A binary tree X is flip equivalent to a binary tree Y if and only if we can make X equal to Y after some number of flip operations.

Given the roots of two binary trees root1 and root2, return true if the two trees are flip equivalent or false otherwise.

Flip Equivalent Binary Trees 解題教學:3 種解法完整比較|LeetCode 951 Best Practice Read More »

Leetcode, 技術文章, , , ,
Same Tree 解題教學示意圖|LeetCode 100

Same Tree 解題教學:3 種解法完整比較|LeetCode 100 Best Practice

Given the roots of two binary trees p and q, write a function to check if they are the same or not.

Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.

Same Tree 解題教學:3 種解法完整比較|LeetCode 100 Best Practice Read More »

Leetcode, 技術文章, , , ,
Encode and Decode Strings 解題教學示意圖|LeetCode 271

Encode and Decode Strings 解題教學:3 種解法完整比較|LeetCode 271 Best Practice

Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings.

Encode and Decode Strings 解題教學:3 種解法完整比較|LeetCode 271 Best Practice Read More »

Leetcode, 技術文章, , , ,
Palindromic Substrings 解題教學示意圖|LeetCode 647

Palindromic Substrings 解題教學:3 種解法完整比較|LeetCode 647 Best Practice

Given a string s, return the number of palindromic substrings in it.

A string is a palindrome when it reads the same backward as forward.

A substring is a contiguous sequence of characters within the string.

Palindromic Substrings 解題教學:3 種解法完整比較|LeetCode 647 Best Practice Read More »

Leetcode, 技術文章, , ,
Valid Palindrome 解題教學示意圖|LeetCode 125

Valid Palindrome 解題教學:3 種解法完整比較|LeetCode 125 Best Practice

A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.

Given a string s, return true if it is a palindrome, or false otherwise.

Valid Palindrome 解題教學:3 種解法完整比較|LeetCode 125 Best Practice Read More »

Leetcode, 技術文章, , ,
Maximum Depth of Binary Tree 解題教學示意圖|LeetCode 104

Maximum Depth of Binary Tree 解題教學:3 種解法完整比較|LeetCode 104 Best Practice

Given the root of a binary tree, return its maximum depth.

A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

Maximum Depth of Binary Tree 解題教學:3 種解法完整比較|LeetCode 104 Best Practice Read More »

Leetcode, 技術文章, , , ,
Valid Parentheses 解題教學示意圖|LeetCode 20

Valid Parentheses 解題教學:3 種解法完整比較|LeetCode 20 Best Practice

Given a string s containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid.

An input string is valid if:

Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Every close bracket has a corresponding open bracket of the same type.

Valid Parentheses 解題教學:3 種解法完整比較|LeetCode 20 Best Practice Read More »

Leetcode, 技術文章, , , ,
Group Anagrams 解題教學示意圖|LeetCode 49

Group Anagrams 解題教學:3 種解法完整比較|LeetCode 49 Best Practice

Given an array of strings strs, group the anagrams together. You can return the answer in any order.

An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

Group Anagrams 解題教學:3 種解法完整比較|LeetCode 49 Best Practice Read More »

Leetcode, 技術文章, , , ,