原创 Find Peak Element,Longest Substring Without Repeating Characters

Find Peak Element 根據題目描述可知,相鄰元素不相同,有且只有一個峯值(這個峯值一定是最大值,不過分析出該條件沒有用,哈哈) 只需尋找峯值即可,二分,每次比較中點及與中點相鄰的元素即可(因爲相鄰元素不相同) 細節處理:區間

原创 Max Points on a Line

Max Points on a Line 可優化時間到O(n^2) (如果用unordered_map做存儲的話)(map做存儲的話是O(n^2 * logn),查找需要O(logn) ) 以一個點爲基準,遍歷其他點,存儲 x,y 座標差

原创 Intersection of Two Linked Lists,Search a 2D Matrix,Set Matrix Zeroes,Combinations,Spiral Matrix

Intersection of Two Linked Lists 簡單鏈表,此題解法很多,題目要求不能改變原始鏈表結構,那麼就只能遍歷到結尾,時間O(m+n)即可,空間可以O(1) Search a 2D Matrix 兩次二分搜索而已

原创 Maximum Gap

Maximum Gap Analysis written by @porker2008. Suppose there are N elements and they range from A to B. Then the maximu

原创 Edit Distance 動態規劃

Edit Distance 思路來源:https://oj.leetcode.com/discuss/10426/my-o-mn-time-and-o-n-space-solution-using-dp-with-explanation

原创 Excel Sheet Column Title,Excel Sheet Column Number

Excel Sheet Column Title 相當於十進制轉換爲26進制,不過注意轉換後的26進制沒有0元素,注意細節轉換即可 Excel Sheet Column Number 反向比較簡單

原创 Minimum Window Substring

Minimum Window Substring 用一個滑動的窗口尋找,注意記錄下 T 中各個字母的個數,並存放在字典中,提高查找效率 滑動窗口: 先從左邊開始增大,直到包含了 T 中所有字母(注意包括重複個數) 然後嘗試縮小窗口,從左邊

原创 Substring with Concatenation of All Words

Substring with Concatenation of All Words 用哈希表記錄各個單詞出現的次數即可

原创 Majority Element

Majority Element Runtime: O(n2) — Brute force solution: Check each element if it is the majority element.Runtime: O(n)

原创 Dungeon Game 動態規劃

Dungeon Game 這題用動態規劃 提示: 從右下角的位置開始計算 每一個格子中的數字取決於其右邊和下邊的計算結果,並和格子中原來的數字做計算得到

原创 Factorial Trailing Zeroes

Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should

原创 Largest Number

Largest Number Given a list of non negative integers, arrange them such that they form the largest number. For example

原创 Permutations II,Sudoku Solver,Merge k Sorted Lists

Permutations II 思路同 Permutations 那題相同,只需多加一條判斷即可 Sudoku Solver 簡單棧操作 Merge k Sorted Lists 合併排序K個有序序列 兩兩合併,再兩兩合併。。。 若所

原创 Maximal Rectangle

Maximal Rectangle 尋找最大的矩形,一開始最沒有思路的一道題 這題可以轉化爲 Largest Rectangle in Histogram 將每一行進行轉換,逐行計算即可

原创 Copy List with Random Pointer

Copy List with Random Pointer 關鍵在如何記錄 Random Pointer 而且要對應 方法如下: 原來的鏈表假設爲:1 --> 2 --> 3 --> 4 --> None 新建的節點插入到這個鏈表中,變成