![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode题解
文章平均质量分 51
ZTao-z
这个作者很懒,什么都没留下…
展开
-
LeetCode 题解:22. Generate Parentheses
22. Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:output:[ "((()))",...原创 2018-09-11 12:46:49 · 144 阅读 · 0 评论 -
LeetCode 题解:474. Ones and Zeroes
n the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.For now, suppose you are a dominator of m 0s and n 1s respectively. On the other ha...原创 2018-10-28 21:03:04 · 263 阅读 · 0 评论 -
LeetCode 题解:338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example:For num = 5 you s...原创 2018-10-24 09:20:45 · 148 阅读 · 0 评论 -
LeetCode 题解:494. Target Sum
You are given a list of non-negative integers, a1, a2, …, an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.Find out how many...原创 2018-10-30 22:38:23 · 132 阅读 · 0 评论 -
LeetCode 题解:84. Largest Rectangle in Histogram
Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each b...原创 2018-11-10 16:34:42 · 141 阅读 · 0 评论 -
LeetCode 题解:85. Maximal Rectangle
Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area.Example:Input:[ ["1","0","1","0","0"], ["1","0","1",原创 2018-11-14 21:18:13 · 163 阅读 · 0 评论 -
LeetCode 题解:152. Maximum Product Subarray
Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation: [2,3] has ...原创 2018-11-24 23:11:31 · 155 阅读 · 0 评论 -
LeetCode 题解:264. Ugly Number II
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.Example:Input: n = 10Output: 12Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 ...原创 2018-12-02 23:58:46 · 133 阅读 · 0 评论 -
LeetCode题解:309. Best Time to Buy and Sell Stock with Cooldown
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 as many transactions as you like (ie, buy one a...原创 2018-12-09 20:02:41 · 448 阅读 · 0 评论 -
LeetCode题解:91. Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given a non-empty string containing only digits, determine the ...原创 2018-12-16 23:57:27 · 156 阅读 · 0 评论 -
LeetCode 题解:111. Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Note: A leaf is a node with no children....原创 2018-10-10 18:16:24 · 95 阅读 · 0 评论 -
LeetCode 题解:452. Minimum Number of Arrows to Burst Balloons
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it’s horizontal, y-coordin...原创 2018-10-16 21:05:35 · 240 阅读 · 0 评论 -
LeetCode 题解:239. Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window m...原创 2018-10-09 15:53:14 · 147 阅读 · 0 评论 -
LeetCode 题解:209. Minimum Size Subarray Sum
209. Minimum Size Subarray SumGiven an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn’t one, return 0 inst...原创 2018-09-08 22:42:57 · 235 阅读 · 0 评论 -
LeetCode 题解:4. Median of Two Sorted Arrays
4. Median of Two Sorted ArraysThere are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+...原创 2018-09-09 09:15:05 · 140 阅读 · 0 评论 -
LeetCode 题解:57. Insert Interval
57. Insert IntervalGiven a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to thei...原创 2018-09-15 21:39:11 · 132 阅读 · 0 评论 -
LeetCode 题解:845. Longest Mountain in Array
845. Longest Mountain in ArrayLet’s call any (contiguous) subarray B (of A) a mountain if the following properties hold:B.length >= 3 There exists some 0 < i < B.length - 1 such that B[...原创 2018-09-17 16:09:17 · 209 阅读 · 0 评论 -
LeetCode 题解:785. Is Graph Bipartite?
Given an undirected graph, return true if and only if it is bipartite.Recall that a graph is bipartite if we can split it’s set of nodes into two independent subsets A and B such that every edge in t...原创 2018-09-25 20:19:02 · 377 阅读 · 0 评论 -
LeetCode 题解:231. Power of Two
Given an integer, write a function to determine if it is a power of two.解题思路牛逼的解法,不解释,直接看代码C++代码class Solution {public: bool isPowerOfTwo(int n) { if(n <= 0) return false; ...原创 2018-09-25 20:24:39 · 156 阅读 · 0 评论 -
LeetCode 题解:19. Remove Nth Node From End of List
19. Remove Nth Node From End of ListGiven a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removi...原创 2018-09-23 07:52:13 · 142 阅读 · 0 评论 -
LeetCode 题解:154. Find Minimum in Rotated Sorted Array II
154. Find Minimum in Rotated Sorted Array IISuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).Find...原创 2018-09-23 08:09:47 · 166 阅读 · 0 评论 -
LeetCode 题解:42. Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.The above elevation map is represented by array ...原创 2018-10-02 12:22:47 · 156 阅读 · 0 评论 -
算法题:跳台阶(2)
一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。C++代码class Solution {public: int jumpFloorII(int number) { int arr[100000] = {0,1,2}; for(int i = 3; i <= number; i++) ...原创 2019-03-28 16:50:57 · 134 阅读 · 0 评论