本次题解包括
- 84. Largest Rectangle in Histogram
- 85. Maximal Rectangle
leetcode Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).
For example, S =
"ADOBECODEBANC"
T ="ABC"
Minimum window is
"BANC"
.Note: If there is no such window in S that covers all characters in T, return the emtpy string
""
.If there are multiple such windows, you are guaranteed that there will always be only one unique minimum window in S.
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
Note: You are not suppose to use the library's sort function for this problem.
Follow up: A rather straight forward solution is a two-pass algorithm using counting sort. First, iterate the array counting number of 0's, 1's, and 2's, then overwrite array with total number of 0's, then 1's and followed by 2's.
Could you come up with an one-pass algorithm using only constant space?
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.
Follow up:Did you use extra space? A straight forward solution using O(_m__n_) space is probably a bad idea. A simple improvement uses O(m + n) space, but still not the best solution. Could you devise a constant space solution?
Given an absolute path for a file (Unix-style), simplify it.
For example, path =
"/home/"
, =>"/home"
path ="/a/./b/../../c/"
, =>"/c"
Corner Cases:
- Did you consider the case where path =
"/../"
? In this case, you should return"/"
.- Another corner case is the path might contain multiple slashes
'/'
together, such as"/home//foo/"
. In this case, you should ignore redundant slashes and return"/home/foo"
.
本文推荐一些wordprss插件
leetcode Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
For example, Given the following matrix:
[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]
You should return
[1,2,3,6,9,8,7,4,5]
.
Implement regular expression matching with support for
'.'
and'*'
.'.' Matches any single character. '*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
The function prototype should be: bool isMatch(const char s, const char p)
Some examples: isMatch("aa","a") → false isMatch("aa","aa") → true isMatch("aaa","aa") → false isMatch("aa", "a") → true isMatch("aa", ".") → true isMatch("ab", ".") → true isMatch("aab", "ca*b") → true