原创 LeetCode題目難度頻率分佈

              1 Two Sum 2 5 array sort         set Two Pointer

原创 LeetCode: Letter Combinations of a Phone Number

題目: https://oj.leetcode.com/problems/letter-combinations-of-a-phone-number/ 分析: DFS 代碼: class Solution { public: vec

原创 LeetCode: Remove Duplicates from Sorted List II

題目 https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ 分析 1. 雙指針來實現, 左側的指針指向上一個有效結點, 右側的指針進行試探, 直到

原创 標準二分查找代碼

二分查找算法在各種場合下經常會用到,在此總結一下它的標準代碼。 代碼 int binary_search(int array[], int n, int value) { int left = 0; int right = n -

原创 LeetCode: Remove Duplicates from Sorted Array II

題目 https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ 分析 和Remove Duplicates from Sorted Array類似,

原创 LeetCode: Regular Expression Mathing

題目 https://oj.leetcode.com/problems/regular-expression-matching/ 分析 1. 普通字符和'.'的匹配很好解決, 直接匹配即可, 關鍵是'*'如何進行匹配 2. 一開始我的想

原创 LeetCode: Remove Nth Node From End of List

題目 https://oj.leetcode.com/problems/remove-nth-node-from-end-of-list/ 分析 1. 兩個指針, 第一個指針先走n步, 然後兩個指針一起走, 直到第一個指針走到結尾處,

原创 LeetCode: Remove Duplicates from Sorted List

題目 https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/ 分析 從前向後遍歷即可 代碼 class Solution { public: List

原创 LeetCode: Search in Rotated Sorted Array

題目 https://oj.leetcode.com/problems/search-in-rotated-sorted-array/ 分析 還是運用二分的思想, 每次循環判斷target在中點的左側還是右側,每次砍掉一半的查找範圍,

原创 LeetCode: Divide Two Integers

題目 https://oj.leetcode.com/problems/divide-two-integers/ 分析 1. 題目要求實現除法運算且不能用乘除和取餘運算, 一開始想用的遞減計數的方式, 顯然這種方法效率太低了, 從而導致

原创 2014年美團校招筆試題解(更新ING……)

前幾天參加了美團的校招筆試, 結果狀態不好, 答得跟屎一樣, 現在考完了總結一下好了。 5. 旋轉二維數組 分析 就是一道找規律的題 代碼 #include <iostream> using namespace std; #

原创 LeetCode: Remove Duplicates from Sorted Array

題目 https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/ 分析 從前向後遍歷, 如果該元素不和前面元素重複, 就該元素排到前面。 代碼 class

原创 C++: 生成100萬隨機數, 排序後保存到文件中

簡介 這大概是大二數據結構課上老師佈置的一個作業, 當年忙着打DOTA所以直接抄同學的, 今天補上。。。 代碼 #include <iostream> #include <vector> #include <algorithm> #in

原创 LeetCode: Search for a Range

題目 https://oj.leetcode.com/problems/search-for-a-range/ 分析 時間複雜度O(log n), 多半便是二分查找的題目。 題目要求找出一個範圍,無非就是找到一個起始點和一個終止點,通過

原创 11種常見排序算法總結(更新ING...)

1. 冒泡排序 (Bubble Sort)  [1] 1.1 算法描述 冒泡排序過程中, 從前往後依次掃描每一對相鄰元素, 一旦發現逆序即交換二者的位置。  這一過程稱作一趟掃描交換。 以此類推, 最多進行n-1趟掃描交換, 整個序列