金若愚的blog

你好


  • 首页

  • 标签

  • 分类

  • 归档

Largest Rectangle in Histogram

发表于 2017-11-20 | 阅读次数:
字数统计: 1,118 | 阅读时长 ≈ 6

84. Largest Rectangle in Histogram

Reference: http://www.geeksforgeeks.org/largest-rectangle-under-histogram/

1. Description:

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.

img

Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].

img

The largest rectangle is shown in the shaded area, which has area = 10 unit.

阅读全文 »

LeetCode221

发表于 2017-11-20 | 阅读次数:
字数统计: 456 | 阅读时长 ≈ 3

221. Maximal Square

Reference: https://discuss.leetcode.com/topic/20801/extremely-simple-java-solution

Thanks jaqenhgar ! Really F**king Genius.

1. Description:

Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.

For example, given the following matrix:

1
2
3
4
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0

Return 4.

阅读全文 »

LeetCode121

发表于 2017-11-20 | 阅读次数:
字数统计: 317 | 阅读时长 ≈ 2

121. Best Time to Buy and Sell Stock

1. Description:

Say you have an array for which the ith element is the price of a given stock on day i.

If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Example 1:

1
2
3
4
Input: [7, 1, 5, 3, 6, 4]
Output: 5

max. difference = 6-1 = 5 (not 7-1 = 6, as selling price needs to be larger than buying price)

Example 2:

1
2
3
4
Input: [7, 6, 4, 3, 1]
Output: 0

In this case, no transaction is done, i.e. max profit = 0.

阅读全文 »

LeetCode32

发表于 2017-11-19 | 阅读次数:
字数统计: 987 | 阅读时长 ≈ 5

32. Longest Valid Parentheses

1. Description:

Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.

For "(()", the longest valid parentheses substring is "()", which has length = 2.

Another example is ")()())", where the longest valid parentheses substring is "()()", which has length = 4.

阅读全文 »

Hello World

发表于 2017-01-21 | 阅读次数:
字数统计: 78 | 阅读时长 ≈ 1

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

1…45
金若愚

金若愚

25 日志
11 标签
RSS
GitHub 微博 匹兹堡 E-Mail
© 2018 金若愚
由 Hexo 强力驱动
|
主题 — NexT.Pisces v5.1.3