Merge Sort 是一種透過切分資料再一一合併的排序演算法。 Merge Sort 有使用到 Divide and Conquer 與 Recursion...
121. Best Time to Buy and Sell Stock Question You are given an array prices wher...
300. Longest Increasing Subsequence Question Given an integer array nums, return...
70. Climbing Stairs Question You are climbing a staircase. It takes n steps to r...
21. Merge Two Sorted Lists Question You are given the heads of two sorted linked...
206. Reverse Linked List Question Given the head of a singly linked list, revers...
從第二個元素開始,往前比對,如果比前一個元素小,則交換位置,以此類推。 以 [30, 5, 1, 31, 10, 9, 2, 3, 4, 8, 7, 6] 來說...
22. Generate Parentheses Question Given n pairs of parentheses, write a function...
Selection Sort 實作上是遍歷一次陣列,找出最小值,並將最小值與陣列的第一個值交換,以此類推,再遍歷一次陣列 (先前排序好的位置可以略過) 找出最小...
136. Single Number Question Given a non-empty array of integers nums, every elem...
一種排序資料的方式,實務上不太常使用,除了某些特定情境。相對於其他排序方式,Bubble Sort 效能較差。 儘管如此,作為基礎中的基礎,最好還是要理解其概念...
26. Remove Duplicates from Sorted Array Question Given an integer array nums sor...
Linear Search Linear Search 非常常見,甚至在學迴圈時就已經用過了。以下直接給範例練習! Practice - Linear Sear...
10. Regular Expression Matching Question Given an input string s and a pattern p...
Recursion 的定義是一個會呼叫自己的函式。 Recursion 技巧在很多地方都有用到,例如: JSON.stringify & JSON....
將一組資料切分成兩組或多組資料,再用切分後的資料進行處理。此技巧能有效減少時間複雜度。 此技巧大量用於搜尋演算法內,以下用 二分搜尋法 (Binary Sear...
20. Valid Parentheses Question Given a string s containing just the characters '...
42. Trapping Rain Water Question Given n non-negative integers representing an e...
Sliding Window 跟上篇 Multiple Pointers 類似,定義兩個指標,一個是 start,一個是 end。 像是: start...
11. Container With Most Water Question You are given an integer array height of...
Multiple Pointers 技巧是透過建立 pointer 變數代表目前指到哪個位置 (index)。使用兩個 pointer 代表目前查找的位置與範圍...
53. Maximum Subarray Question Given an integer array nums, find the contiguous s...
Frequency Counter 是一種解題技巧,它使用物件的鍵值 (Key) 來記錄陣列或字串裡面特定值的出現次數。它可以避免一直遍歷資料,可以有效減少時間...
15. 3Sum Question Given an integer array nums, return all the triplets [nums[i],...
在 Day 1 我們講到的複雜度表示都是指時間複雜度,在輸入的參數越多越大的情況下,所要執行的步驟(執行所需花費的時間)的增長趨勢。 我們也可以使用 Big O...
5. Longest Palindromic Substring Question Given a string s, return the longest p...
3. Longest Substring Without Repeating Characters (Medium) Question Given a stri...
Big O Notation 是一種表示演算法複雜度的方式。同樣解決一個演算法問題,若該算法執行的時間越少,使用的記憶體愈少,就是越好的解法。可以用來評斷該演算...
1. Two Sum (Easy) Question Given an array of integers nums and an integer target...
本系列將使用 JavaScript 來撰寫程式,文中也會穿插英文讓讀者盡量熟悉這些單詞,未來在看相關題目時能夠幫助理解。 什麼是演算法與資料結構 演算法指...