【leetcode】901. Online Stock Span
题目如下:

解题思路:和【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的更多相关文章
- 【LeetCode】901. Online Stock Span 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 单调递减栈 日期 题目地址:https://leet ...
- 【LeetCode】714、买卖股票的最佳时机含手续费
Best Time to Buy and Sell Stock with Transaction Fee 题目等级:Medium 题目描述: Your are given an array of in ...
- 【leetcode】1021. Best Sightseeing Pair
题目如下: Given an array A of positive integers, A[i]represents the value of the i-th sightseeing spot, ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【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 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 27. Remove Element【leetcode】
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...
- 【刷题】【LeetCode】007-整数反转-easy
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
- 【刷题】【LeetCode】000-十大经典排序算法
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法
随机推荐
- 如何做好APP功能测试?
一.如何做好app的测试工作? 22 个回答  斗魂大陆 凡是可能会出错的地方,一定会出错!--墨菲法则 腾讯有个平台可以实现适配兼容.服务器压力.性能测试.弱网络.耗电量测试等等,挺全面的.WeT ...
- XP定位(APP元素定位)
Appium app自动化测试经验分享-Xpath定位总结 在我看来,自动化测试中元素定位的倚天剑和屠龙刀莫过于 Xpath和CSS,但CSS只用于Web(之前已经分享过),这次就分享下Xpath的定 ...
- Angular JS - 1 - 环境准备
1.webstorm 下载安装 webstorm 同 intellij IDEA 一样智能好用~ 智能的同时,比较费内存 2. chrome插件安装 按照下图,打开扩展程序,选择开发者模式: 下载n ...
- AcWing 248. 窗内的星星 (扫描线)打卡
题目:https://www.acwing.com/problem/content/250/ 题意:给你n个点,现在问你能每个点都有个权值,问你能覆盖最多的权值是多少,边界不算 思路:这个其实和我之前 ...
- Python Django 编写一个简易的后台管理工具4-添加admin模版
导入admin后台模版 可以在网上任意搜索模版,我这里也提供一个地址github 拷贝admin后台的html文件至项目的templates文件夹 创建static文件夹,将admin后台的js,im ...
- SetWindowsHookEx 其他进程的 记录
SetWindowsHookEx( WH_GETMESSAGE,CallWndProc, HInstance, h2); WH_GETMESSAGE 这个类型 hook 其他窗体的 线程是正常的 ...
- 支付宝PC端接入PHP
引入支付宝接口 放入一个插件库中,方便管理 创建支付类 1.发起支付 public function init() { $order_id = $_REQUEST['order_id']; $orde ...
- 12. Jmeter-断言
jmeter-断言介绍与使用 性能测试中较少用到断言.断言会增加脚本执行时间,但是接口测试中断言是必备的.什么是断言?其实就是功能测试中常说的预期结果和实际结果是否相等. 响应断言 JSON Asse ...
- Spark Streaming + Kafka 整合向导之createDirectStream
启动zk: zkServer.sh start 启动kafka:kafka-server-start.sh $KAFKA_HOME/config/server.properties 创建一个topic ...
- C++中的异常处理(下)
1,catch 语句块中可以抛出异常: 1,示意图: 2,func() 在 try 语句块中,说明它有可能抛出异常,抛出的异常有可能是整型或其它类型: 3,catch 语句块处理方式是将异常重新抛出去 ...