【leetcode】915. Partition Array into Disjoint Intervals
题目如下:

解题思路:题目要求的是在数组中找到一个下标最小的index,使得index左边(包括自己)子序列的最大值小于或者等于右边序列的最小值。那么我们可以先把数组从最左边开始到数组最右边所有子序列的最大值都求出来存入leftMax数组,同时也把从数组最右边开始到最左边的所有子序列的最小值求出来存入rightMin数组,最后找出最小的i使得leftMax[i] <= rightMin[i+1]即可。
代码如下:
class Solution(object):
def partitionDisjoint(self, A):
"""
:type A: List[int]
:rtype: int
"""
leftMax = [0] * len(A)
rightMin = [0] * len(A)
for i in range(len(A)):
if i == 0:
leftMax[i] = A[i]
else:
leftMax[i] = max(leftMax[i-1],A[i]) for i in range(-1,-len(A)-1,-1):
if i == -1:
rightMin[i] = A[i]
else:
rightMin[i] = min(rightMin[i + 1], A[i]) #print leftMax,rightMin
res = 0
for i in range(len(leftMax)-1):
if leftMax[i] <= rightMin[i+1]:
res = i
break return res + 1
【leetcode】915. Partition Array into Disjoint Intervals的更多相关文章
- 【LeetCode】915. Partition Array into Disjoint Intervals 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/partitio ...
- [LeetCode] 915. Partition Array into Disjoint Intervals 分割数组为不相交的区间
Given an array A, partition it into two (contiguous) subarrays left and right so that: Every element ...
- 【leetcode】352. Data Stream as Disjoint Intervals
问题描述: Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers ...
- 【LeetCode】1020. Partition Array Into Three Parts With Equal Sum 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【leetcode】1043. Partition Array for Maximum Sum
题目如下: Given an integer array A, you partition the array into (contiguous) subarrays of length at mos ...
- 【leetcode】1020. Partition Array Into Three Parts With Equal Sum
题目如下: Given an array A of integers, return true if and only if we can partition the array into three ...
- 【LeetCode】659. Split Array into Consecutive Subsequences 解题报告(Python)
[LeetCode]659. Split Array into Consecutive Subsequences 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id ...
- 【LeetCode】86. Partition List 解题报告(Python)
[LeetCode]86. Partition List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:// ...
- 【leetcode】698. Partition to K Equal Sum Subsets
题目如下: 解题思路:本题是[leetcode]473. Matchsticks to Square的姊妹篇,唯一的区别是[leetcode]473. Matchsticks to Square指定了 ...
随机推荐
- Python基础教程(019)--执行Python的方式,IPython
前言 了解IPython 内容 IPython 是一个Python的交互式shell,比默认的Python shell 好用的多 查看图片 在提示符下执行 目的 了解进入IPython 退出IPyth ...
- react教程 — 性能优化
参考:https://segmentfault.com/a/1190000007811296?utm_medium=referral&utm_source=tuicool 或 https: ...
- python-zx笔记3-函数
一.调用函数 在交互式命令行通过help(abs)查看abs函数的帮助信息 把函数名赋给一个变量 a = abs 二.定义函数 求解方程:ax2 + bx + c = 0 # -*- coding: ...
- php 统计每天价格,货币种类,汇总得算法和数据处理 (后端和前段实现自动统计价格和币种类型)
整体实现逻辑介绍 1.对查询数据做一个总体查询,需要根据查询自己主要业务逻辑数据. 2.对总体查询数据和时间和币种类型做三部分数据处理. 3.总体查询数据按照币种和日期组装二维数据对应得键值是价格. ...
- appium定位学习
前面也介绍过appium的一些定位方法,今天看到一篇博客,里面的方法总结的,就转载过来. 本文转自:https://www.cnblogs.com/Mushishi_xu/p/7685966.html ...
- (二)linux内核准备及编译
1. 内核下载地址 linux内核网站,可以拿到最新的和最近的稳定版本内核: https://www.kernel.org/ 通过网站下载压缩包后解压或者使用git下载到本地: git clone h ...
- xcodebuild自动打包上传到蒲公英的shell脚本
注意: ExportOptions.plist (包含了证书相关信息) 该plist 文件可以通过xcode手动导出ipa之后获取到, 区分appstore 和 development的情况 #! / ...
- TestStack.White安装详解
一.安装 NuGet TestStack.White是通过NuGet进行安装的.NuGet最低支持VS2010.我使用的VS2015. 安装方式一 :从Visual Studio的工具->扩展和 ...
- 控件识别工具Inspect.exe下载
一.Inspect.exe 控件识别工具.官网上说通过下载安装Windows SDK后,可以在目录C:\Program Files (x86)\Microsoft SDKs\Windows Kits\ ...
- nginx的配置系统
nginx的配置系统由一个主配置文件和其他一些辅助的配置文件构成.这些配置文件均是纯文本文件,全部位于nginx安装目录下的conf目录下. 配置文件中以#开始的行,或者是前面有若干空格或者TAB,然 ...