【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指定了 ...
随机推荐
- 【leetcode】399. Evaluate Division
题目如下: Equations are given in the format A / B = k, whereA and B are variables represented as strings ...
- Fmx在android下InputBox输入框点击Cancel取消按钮后报异常
在网上搜索半天也没有找到相关信息,估计遇到这个问题的相当少, 解决办法: 找到FMX.Dialogs.Android.pas, 将121行中 FValues[I] := FDefaultValues ...
- JMeter简单使用
JMeter是apache公司基于java开发的一款开源压力测试工具.因为它是java开发的,所以运行的时候必须要安装jdk才可以:Jmeter是免安装的,所以拿到安装包后直接解压就可以使用了,它也是 ...
- LDD3 第7章 Time,Delays and Deferred Work
处理时间委托包括如下任务,按复杂度依次上升: 测量时间流失和比较时间 知道当前时间 指定时间量的延时操作 调度异步函数在之后的时间发生 一.测量时间流失 系统定时硬件规律的产生定时器中断,在内核启动阶 ...
- SDUT 1266 出栈序列统计(卡特兰数)
这道题是回溯算法,网上一查是卡特兰数先占上代码,题解过两天会写. #include <bits/stdc++.h> using namespace std; int main() { // ...
- Java总结第二期
大家好,我又来了!!啦啦,我知道你们很想我,很想我赶快写更多的文章来提高自己的水平,好吧,我就从了你们.下面跟我一起来光顾Java第二期,掌声,掌声!!! 第二章: 这章,我要给大家讲得内容有变量,常 ...
- sts bug SpringJUnit4ClassRunner
SpringJUnit4ClassRunner找不到,不会自动修复, 只能复制引用过去 import org.springframework.test.context.junit4.SpringJUn ...
- meta标签 使用说明(http-equiv、refresh、seo)
meta标签 使用说明(http-equiv.refresh.seo) meta标签,是在head标签里面,一般用做页面描述的.它的内容,用来描述页面一些信息的,如类型.编码.作者.简介等!虽然,它不 ...
- English-Difference between original and source
最近跟网页翻译怼上了,在给翻译前的页面起名是纠结于使用 original page 还是 source page,就查了一下 original 和 source 的区别. original: n. 原 ...
- exporter
何为 Prometheus Exporter? Prometheus 监控基于一个很简单的模型: 主动抓取目标的指标接口(HTTP 协议)获取监控指标, 再存储到本地或远端的时序数据库. Promet ...