
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 larges...原创 2018-08-04 22:13:03 · 134 阅读 · 0 评论 -
未排序数组的O(n)问题
输入一组未排序的整数,找出其中最长的连续数字的长度。例如输入为[3,1,2,5,7,4,8,9] ,其中连续的数据为1,2,3,4,5,长度为5 。要求算法时间复杂度为O(n). 思路:存到hashset里面,然后依次遍历,如果当前数为连续数字的起始数字(即num-1不属于set),那么就开始往后看 import java.util.*; public class Main{ pub...原创 2018-08-09 15:03:58 · 533 阅读 · 0 评论 -
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: 6 Explanation: [2,3] h...原创 2018-07-27 20:41:09 · 158 阅读 · 0 评论 -
Best Time to Buy and Sell Stock
1.只能买入卖出一次。 思路:卖出时,在前面最低价的时候买入,可以用一个变量记录最低价。 class Solution { public int maxProfit(int[] prices) { if(prices == null||prices.length == 0) return 0; int res = 0; int m...原创 2018-08-02 10:54:34 · 191 阅读 · 0 评论 -
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. 思路:见图 当考虑到图中红色圈起来的数时,依次往上遍历,每次考虑能构成的矩形,图为: 所以第一次遍历标记下从左到右的连续1的个数...原创 2018-08-16 13:26:22 · 320 阅读 · 0 评论 -
221. Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area. 思路:如果当前正在考虑的结点为n+1边长的正方形的右下角顶点,那么这个结点的左上三个点必定为长为n的正方形右下角顶点。 class Solution...原创 2018-08-16 13:35:16 · 206 阅读 · 0 评论 -
数组中的子数组之和问题
560. Subarray Sum Equals K 思路:可以这样考虑,对于求a[i] - a[j]的连续和,可以转化为a[0]-a[j]和a[0]-a[i]的问题,而后者可以在一次遍历时完成,用hashmap存出现相同得数的次数。 class Solution { public int subarraySum(int[] nums, int k) { int...原创 2018-09-01 10:15:20 · 288 阅读 · 0 评论 -
字典树
今日头条 异或 题目描述 给定整数m以及n各数字A1,A2,..An,将数列A中所有元素两两异或,共能得到n(n-1)/2个结果,请求出这些结果中大于m的有多少个。 输入描述: 第一行包含两个整数n,m. 第二行给出n个整数A1,A2,...,An。 数据范围 对于30%的数据,1 <= n, m <= 1000 对于100%的数据,1 <= n, m, A...原创 2018-09-01 17:54:57 · 224 阅读 · 0 评论