题目如下:

解题思路:【leetcode】84. Largest Rectangle in Histogram的核心是一样的,都是要找出当前元素之前第一个大于自己的元素。

代码如下:

class StockSpanner(object):
def __init__(self):
self.cl = []
self.vl = [] def next(self, price):
"""
:type price: int
:rtype: int
"""
count = 1
if len(self.vl) == 0:
self.vl.append(price)
self.cl.append(1)
else:
startInx = len(self.vl) - 1
while startInx >= 0 and price >= self.vl[startInx]:
count += self.cl[startInx]
startInx -= self.cl[startInx]
self.vl.append(price)
self.cl.append(count)
return count

【leetcode】901. Online Stock Span的更多相关文章

  1. 【LeetCode】901. Online Stock Span 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 单调递减栈 日期 题目地址:https://leet ...

  2. 【LeetCode】714、买卖股票的最佳时机含手续费

    Best Time to Buy and Sell Stock with Transaction Fee 题目等级:Medium 题目描述: Your are given an array of in ...

  3. 【leetcode】1021. Best Sightseeing Pair

    题目如下: Given an array A of positive integers, A[i]represents the value of the i-th sightseeing spot, ...

  4. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  5. 【Leetcode】Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  6. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

  7. 27. Remove Element【leetcode】

    27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

  8. 【刷题】【LeetCode】007-整数反转-easy

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...

  9. 【刷题】【LeetCode】000-十大经典排序算法

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法

随机推荐

  1. MySQL执行计划之EXPLAIN基本解释说明

    一.EXPLAIN使用潜规则 explain + sql语句 例如: EXPLAIN SELECT * FROM `t_user`; 二. 表头字段详解 (1) id-----> 表的读取顺序 ...

  2. SSH小应用

    1:Spring整合Hibernate <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hi ...

  3. python 简单抓取网页并写入excel实例

    # -*- coding: UTF-8 -*- import requests from bs4 import BeautifulSoup import xlwt import time #获取第一页 ...

  4. yii2和laravel比较

    yii2和laravel比较 一.总结 一句话总结: 开发速度两者相当:laravel的artisan工具和yii的gii有异曲同工的效果,借助于artisan工具,可以快速创建控制器.模型和路由等. ...

  5. STL排序函数

    Qsort,Sort,Stable_sort,Partial_sort,List::sort 参考

  6. net core 发布docker镜像的官方写法

    使用vscode发布的镜像可能存在不能运行的问题, 可以去docker的官方文档下找一个标准的格式再替换一下就可以用了: FROM mcr.microsoft.com/dotnet/core/sdk: ...

  7. 同步架构OR异步架构

    把智能系统比喻成KFC营业厅,处理器是窗口和窗口后面的服务员(把一个窗口当作一个核心),指令集是后面排队的人,窗口是数据吞吐量.当中午就餐人多的时候,一个窗口肯定忙不过来,这时候可以增加窗口,有两种方 ...

  8. 安装Elasticsearch5.4.0以及head,kibana插件

    可以在网盘中下载也可以去官网下载 网盘: Elasticsearch 地址:http://pan.baidu.com/s/1hrI0AFU elasticsearch-head  地址:http:// ...

  9. List集合--Vector子类

    Vector子类 Vector是一个原始古老的程序类,这个类是在JDK1.0的时候就提供的,而后到了JDK1.2的时候,由于有一部分开发者已经习惯于使用Vector,并且许多的系统类也是基于Vecto ...

  10. 微信小程序实战篇-分类页面制作

    https://blog.csdn.net/u012927188/article/details/73650264