原创 leetcode【216】【tag Array Backtracking】Combination Sum III【c++版本,DFS,時間空間100%】

問題描述: Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be

原创 leetcode【217、218】【tag Array】Contains Duplicate I / II【c++版本,hash用法】

問題描述(217): Given an array of integers, find if the array contains any duplicates. Your function should return true if a

原创 leetcode【172】【tag Math】Factorial Trailing Zeroes【c++版本,時間空間100%】

問題描述: Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explanation: 3! =

原创 leetcode【209】【tag Array】Minimum Size Subarray Sum【c++版本,時間從O(n^2)到O(n)】

問題描述: Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray

原创 leetcode【168、171】【tag Math】Excel Sheet Column Title、Excel Sheet Column Number【c++版本,時間空間100%】

問題描述(168): Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example:

原创 leetcode【87】【tag string】Repeated DNA Sequences【c++版本,時間92%,空間100%,位運算,hash表】

問題描述: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When stu

原创 leetcode【165】【tag string】Compare Version Numbers【c++版本,時間空間100%】

問題描述: Compare two version numbers version1 and version2. If version1 > version2 return 1; if version1 < version2 return

原创 leetcode【151】【tag String】Reverse Words in a String【c++版本,多種解法,翻轉法和巧妙字符串流】

問題描述: Given an input string, reverse the string word by word. Example 1: Input: "the sky is blue" Output: "blue is sky

原创 leetcode【200】【tag DFS】Number of Islands【c++版本,遞歸與非遞歸】

問題描述: Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by wate

原创 leetcode【199】【tag Tree】Binary Tree Right Side View【c++版本,層次遍歷,DFS兩種方法】

問題描述: Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can se

原创 leetcode【198】【tag DP】House Robber【c++版本,動態規劃,時間空間O(n)均100%】

問題描述: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money sta

原创 leetcode【173】Binary Search Tree Iterator【c++版本,多種解法】

問題描述: Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a

原创 leetcode【174】【tag DP】Dungeon Game【c++版本,動態規劃】

問題描述: The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon

原创 leetcode【188】【tag DP】Best Time to Buy and Sell Stock IV【c++版本,時間O(nk)空間O(k)】

問題描述: Say you have an array for which the i-th element is the price of a given stock on day i. Design an algorithm to f

原创 leetcode【169】Majority Element【c++版本,時間87%,數組特點法】

  源碼: 《劍指offer》的第39題,歡迎讀者查看劍指offer總綱。 如果我們回到題目本身仔細分析,如果這個數組已經排序,那麼排序之後位於數組中間的數字一定就是那個出現次數超過數組長度一半的數字。也就是說,這個數字是統計學上的中位數