题目如下:

解题思路:题目要求的是在数组中找到一个下标最小的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的更多相关文章

  1. 【LeetCode】915. Partition Array into Disjoint Intervals 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/partitio ...

  2. [LeetCode] 915. Partition Array into Disjoint Intervals 分割数组为不相交的区间

    Given an array A, partition it into two (contiguous) subarrays left and right so that: Every element ...

  3. 【leetcode】352. Data Stream as Disjoint Intervals

    问题描述: Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers ...

  4. 【LeetCode】1020. Partition Array Into Three Parts With Equal Sum 解题报告(Python)

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

  5. 【leetcode】1043. Partition Array for Maximum Sum

    题目如下: Given an integer array A, you partition the array into (contiguous) subarrays of length at mos ...

  6. 【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 ...

  7. 【LeetCode】659. Split Array into Consecutive Subsequences 解题报告(Python)

    [LeetCode]659. Split Array into Consecutive Subsequences 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id ...

  8. 【LeetCode】86. Partition List 解题报告(Python)

    [LeetCode]86. Partition List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:// ...

  9. 【leetcode】698. Partition to K Equal Sum Subsets

    题目如下: 解题思路:本题是[leetcode]473. Matchsticks to Square的姊妹篇,唯一的区别是[leetcode]473. Matchsticks to Square指定了 ...

随机推荐

  1. java获取当月日期 和 周末

    /** * java获取 当月所有的日期集合 * @return */public static List<Date> getDayListOfMonth() { List list = ...

  2. Kafka长文总结

    Kafka是目前使用较多的消息队列,以高吞吐量得到广泛使用 特点: 1.同时为发布和订阅提供搞吞吐量.Kafka的设计目标是以时间复杂度为O(1)的方式提供消息持久化能力的,即使对TB级别以上数据也能 ...

  3. 查看mysql数据库文件存放位置

    show variables like '%basedir%' 也是可以的,这是查找mysql的安装路径

  4. 【Dart学习】--Dart之超级父类之Object

    一,概述 -- Object Dart语言和Java一样,都是面向对象语言,所有的类也都有个公共的父类----->Object.该类位于Dart sdk核心库core目录下. 二,构造方法 // ...

  5. springBootJpa 联表分页查询总数不准的问题

    问题情景: 在联表查询时 ``` // 两张表关联查询 Join<Project, Plan> planJoin = root.join("plans", JoinTy ...

  6. 加载的DAL数据访问层的类型

    using System; using System.Collections; using System.Reflection; using CSFrameworkV4_5.Core; using C ...

  7. python外星人入侵(游戏开发)

    实现的项目要求: 1.外星人游戏添加飞船上下移动功能: 2.为游戏添加背景音乐: 3.在玩家得分.最高得分.玩家等级前添加"Score"."High Score" ...

  8. HDU3951_Coin Game

    Coin Game Problem Description 一堆n个硬币围成一圈,两个人轮流拿走连续k个硬币,拿走最后一堆的人获胜 问你第一个人获胜还是第二个 思路: 这是NIM游戏改编版本 但是道理 ...

  9. FVWM使用指南

    www.ctex.org/documents/shredder/fvwm_frame.html

  10. jumpserver4.0centos7安装步骤

    一步一步安装(CentOS) 测试推荐环境 CPU: 64位双核处理器 内存: 4G DDR3 数据库:mysql 版本大于等于 5.6 mariadb 版本大于等于 5.5.6 环境 系统: Cen ...