原创 49. Group Anagrams [Leetcode]

核心思想: 利用mashmap來存儲同構詞對應的字符表。其中每一個key對應着結果vector中字符集所在的index。 運行耗時:26ms class Solution { public: vector<vector<stri

原创 142. Linked List Cycle II [leecode]

 利用 floyd cycle detection原理來解題 分析詳見 博客287. Find the Duplicate Number [Leetcode] 代碼: /** * Definition for singly-linke

原创 153. Find Minimum in Rotated Sorted Array [Leetcode]

用二分查找法來解決: class Solution { public: int findMin(vector<int>& nums) { int left = 0, right = nums.size() - 1

原创 287. Find the Duplicate Number [Leetcode]

這題首先想到的最簡單的方法是用快排然後再遍歷。 然而題目要求不能改變原來的數組順序。 所以快排的方法被排除。 後來想到了用binary search來做。 方法一:Binary Search 由於數字的範圍是確定的[1,n] 取數字mid

原创 makefile中僞目標詳解

僞目標 下面的“clean”目標,是一個“僞目標”,     clean:             rm *.o temp 我們生成了許多文件編譯文件,我們也應該提供一個清除它們的“目標”以備完整地重編譯而用。 (以“make c

原创 Battleships in a Board [Leetcode]

從上到下,從左到右遍歷,遇到X,判斷左邊和上邊是否有X,沒的話則爲新出現的battleship。 class Solution { public: int countBattleships(vector<vector<char>>

原创 靜態鏈接庫LIB和動態鏈接庫DLL

靜態鏈接庫LIB和動態鏈接庫DLL 靜態鏈接庫與動態鏈接庫都是共享代碼的方式,如果採用靜態鏈接庫,則無論你願不願意,lib 中的指令都全部被直接包含在最終生成的 EXE 文件中了。但是若使用 DLL,該 DLL 不必被包含在最終 EXE

原创 leetcode two sum

先用快排,時間複雜度爲nlogn,再在每個循環裏用二分進行查找,時間複雜度爲nlogn,總體時間複雜度爲nlogn class Solution { public: vector<int> twoSum(vector<int>&

原创 189. Rotate Array [Leetcode]

題目: -------------------------------------------------------------------------------------------------------------------