33. Search in Rotated Sorted Array Question There is an integer array nums sorte...
19. Remove Nth Node From End of List Question Given the head of a linked list, r...
55. Jump Game Solution 1: DP (Tail -> Head) class Solution: def canJump(s...
105. Construct Binary Tree from Preorder and Inorder Traversal Solution 1: Recur...
287. Find the Duplicate Number Solution 1: Brute-Force (TLE) class Solution:...
21. Merge Two Sorted Lists Question You are given the heads of two sorted linked...
3. Longest Substring Without Repeating Characters (Medium) Question Given a stri...
17. Letter Combinations of a Phone Number Solution 1: Recursive + DFS class Solu...
142. Linked List Cycle II Solution 1: HashSet class Solution: def detectCycl...
27. Remove Element Solution 1: Two Pointer + Swap class Solution: def remove...
62. Unique Paths Solution 1: DFS (TLE) class Solution: def uniquePaths(self,...
Merge Sort 是一種透過切分資料再一一合併的排序演算法。 Merge Sort 有使用到 Divide and Conquer 與 Recursion...
169. Majority Element Solution 1: Counter from collections import Counter class...
Heap Sort 使用 Binary Heap 處理資料排序,也可視為 Selection Sort 的改良版。 兩者一樣都是將資料分成兩區,一區為排序好的,...
234. Palindrome Linked List Solution 1: Auxiliary array & reversed class Sol...
236. Lowest Common Ancestor of a Binary Tree Solution 1: DFS class Solution:...
200. Number of Islands Solution 1: DFS + Bitmap class Solution: def numIslan...
34. Find First and Last Position of Element in Sorted Array Solution 1: Recursiv...
9. Palindrome Number Question Given an integer x, return true if x is palindrome...
25. Reverse Nodes in k-Group Solution 1: Iterative class Solution: def rever...
Coin Change Problem 如何以最少的硬幣數量來湊出特定金額的錢。 這個問題可以用簡單的方式描述如下: 假設我們有一些不同面額的硬幣,每種面額的硬...
Bucket Sort 和之前的 Radix Sort 有點類似,建立幾個桶子並將資料丟進去排序。而 Bucket Sort 是取區間,例如 1 號桶子裝 0...
14. Longest Common Prefix Question Write a function to find the longest common p...
96. Unique Binary Search Trees Solution 1: DP class Solution: def numTrees(s...
將一組資料切分成兩組或多組資料,再用切分後的資料進行處理。此技巧能有效減少時間複雜度。 此技巧大量用於搜尋演算法內,以下用 二分搜尋法 (Binary Sear...
152. Maximum Product Subarray Solution 1: DP class Solution: def maxProduct(...
從第二個元素開始,往前比對,如果比前一個元素小,則交換位置,以此類推。 以 [30, 5, 1, 31, 10, 9, 2, 3, 4, 8, 7, 6] 來說...
121. Best Time to Buy and Sell Stock Question You are given an array prices wher...
198. House Robber Question You are a professional robber planning to rob houses...
開賽前言 以前都有想過用一種程式語言實作基本演算法,之前試過 C++ 和 Python,不過寫幾天後就沒碰了 :) 這次是透過 Kotlin ~ 以前在 Mo...