题目如下:

解题思路:【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. MYSQL5.7.9改密码相关设置

    Centos7上,对MySQL5.7开启远程连接. 1.修改/etc/my.cnf [mysqld] validate_password=off 2.命令行进入mysql use mysql; GRA ...

  2. python学习笔记(五)文件操作和集合

    文件基本操作: 现有文件file.txt f=open('file.txt','r')#以只读方式打开一个文件,获取文件的句柄,如果是读的话,r可以不写,默认就是只读:文件不存在时,会报错 first ...

  3. XSS漏洞基础

    什么是XSS? XSS全程Cross-site scripting,跨站脚本攻击.恶意攻击者往Web页面里插入html代码,当用户浏览该页之时,嵌入其中Web里面的html代码会被执行,从而达到恶意用 ...

  4. CSD编码----数字信号处理--006

    有符号数(Signed Digit Number , SD) SD编码 1.有三重值 {0,1,-1} 2.应用在不用进位的加法器或乘法器中能够降低复杂性 因为通常可以通过非零元素的数来估计乘法的工作 ...

  5. 基于Socket和OpenCV的实时视频传输

    https://blog.csdn.net/pengz0807/article/details/52204475

  6. BZOJ 3294: [Cqoi2011]放棋子(计数dp)

    传送门 解题思路 设\(f[i][j][k]\)表示前\(k\)个颜色的棋子占领了\(i\)行\(j\)列的方案数,那么转移时可以枚举上一个颜色时占领的位置,\(f[i][j][k]=\sum\lim ...

  7. Unity编程标准导引-1.1下载和安装Unity

    本文为博主原创文章,欢迎转载,请保留出处:http://blog.csdn.net/andrewfan 1.1.下载和安装Unity 1.1.1 选取版本 首先找到Unity官方网站https://s ...

  8. [CSP-S模拟测试]:biology(DP)

    题目传送门(内部题23) 输入格式 第一行有$2$个整数$n,m$.接下来有$n$行,每行$m$个整数,表示$a$数组.接下来有$n$行,每行$m$个整数,表示$b$数组. 输出格式 一行一个整数表示 ...

  9. Python笔记(七)_全局变量与局部变量

    全局变量与局部变量:在函数外部或内部定义的变量 1. 函数内部的变量名首次出现,且在=号左边 不管这个变量在全局域中有没有定义该变量名,都被视为一个局部变量 例1: >>>num=1 ...

  10. mybatis分页插件使用

    一:导入依赖 <!--分页插件--> <dependency> <groupId>com.github.pagehelper</groupId> < ...