
reView
云水谣CS
这个作者很懒,什么都没留下…
展开
-
【DFS】200. Number of Islands
采用DFS的思想,遍历1的聚类簇个数;class Solution {public: void dfs(vector<vector<char>>& grid,vector<vector<bool>>& visit, int row, int col) { int dx[4]={0,-1,0,1}; int dy...原创 2018-07-18 22:59:29 · 128 阅读 · 0 评论 -
229. Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.Note: The algorithm should run in linear time and in O(1) space.Example 1:Input: [3,2,3]Output: [3]Exa...原创 2018-12-28 12:43:48 · 158 阅读 · 0 评论 -
188. Best Time to Buy and Sell Stock IV
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most k transactions.Note:You may not eng...原创 2018-12-24 23:07:31 · 122 阅读 · 0 评论 -
【DP】300. Longest Increasing Subsequence
时间复杂度为o(n**2)时:class Solution: def lengthOfLIS(self, nums): """ :type nums: List[int] :rtype: int """ if len(nums)==0: return 0 ...原创 2018-07-21 21:02:07 · 144 阅读 · 0 评论 -
673. Number of Longest Increasing Subsequence
Given an unsorted array of integers, find the number of longest increasing subsequence.Example 1:Input: [1,3,5,4,7]Output: 2Explanation: The two longest increasing subsequence are [1, 3, 4, 7] ...转载 2018-12-25 22:50:57 · 161 阅读 · 0 评论 -
【贪心】406. Queue Reconstruction by Height
C++版:class Solution {public: static bool cmp(pair<int,int> A, pair<int,int> B) { if(A.first!=B.first) return A.first>B.first; else ...原创 2018-07-21 17:15:18 · 179 阅读 · 0 评论 -
42. Trapping Rain Water
思路转自https://blog.youkuaiyun.com/makuiyu/article/details/43650365:class Solution {public: int trap(vector<int>& height) { int left=0,right=height.size()-1; int ans=0; ...转载 2018-05-13 20:48:50 · 203 阅读 · 0 评论 -
23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->2->3->4-...转载 2019-01-03 13:34:45 · 172 阅读 · 0 评论 -
264. Ugly Number II
题目描述把只包含质因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含质因子7。 习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第N个丑数。Example:Input: n = 10Output: 12Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of th...原创 2018-09-30 20:29:21 · 254 阅读 · 0 评论