`
文章列表
[分析] 思路1:逆序遍历字符串,数字和右括号保存在一个堆栈stack1中,运算符保存在另一个堆栈stack2中,跳过空格,遇到左括号时计算stack1中首个右括号之上的所有数据,也即当前括号对中的内容。 在Accept之前有两个出错点:1)采用顺序遍历。出错case:2-1+1,因为加减的运算顺序是从左至右;2)逆序遍历时拼接完一个位数大于1的完整int 后要逆序已得到实际数值。出错case: 2147483647 思路2:参考如下两篇文章 https://leetcode.com/discuss/41868/java-solution-stack https://leetcode.com/d ...
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead. For example, given the array [2,3,1,2,4,3] and s = 7,the subarray [4,3] has the minimal length under the problem constraint. [balabala] ...
Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int. [分析]  常规思路:判断两个矩形是否有重叠,无重叠返回面积加和即可,有重叠检查是否是 ...
Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h. [分析] [思路1]直接递归时间复杂度是2^h 级别,超时,需要些 ...
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i and j i
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = "aabcc",s2 = "dbbca", When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", return false.  [balabala]  像所有题目一样, ...
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. '*' Matches any sequence of characters (including the empty sequence). The matching should cover the entire input string (not partial). The function prototype should be: bool isMatch(const c ...
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area. For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 Return 4. [balabala] 此题是Maximal Rectangle的变形题,思路仍然是求解各行为底的直方图中的最大正方形面积然后取最大值。求解某一行为底的直方图中的最大正方形面 ...
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k = 2, return 5. Note: You may assume k is always valid, 1 ≤ k ≤ array's length. // method 1: O(nlogn) publ ...
Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For example, given s = "aab",Return 1 since the palindrome partitioning ["aa","b"] could be produce ...
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = "aab", Return   [     ["aa","b"],     ["a","a","b"]   ] [分析] 递归尝试所有的分割法。分割 ...
Note: This is an extension of House Robber. After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all houses at this place are arranged in a circle. That means the first house is the neighbor of th ...
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. [balabala] 这题想到借用Largest Rectangle in Histogram的思路就比较简单了。计算行 i 时,以这行为底,计算每一列对应的“高度”,若某列元素为0,则高度为0,若为1,则高度=同列上一行高度 + 1。得出每列高度后,应用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 bar is 1, given height = [2,1,5,6,2,3].   The largest rectangle is shown in the shaded area, w ...
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: Given m, n satisfy the following condition: 1 ≤ m ≤ n ≤ length of list.   public ListNode reverseB ...
Global site tag (gtag.js) - Google Analytics