[leetcode-915-Partition Array into Disjoint Intervals]
Given an array A, partition it into two (contiguous) subarrays left and right so that:
- Every element in
leftis less than or equal to every element inright. leftandrightare non-empty.lefthas the smallest possible size.
Return the length of left after such a partitioning. It is guaranteed that such a partitioning exists.
Example 1:
Input: [5,0,3,8,6]
Output: 3
Explanation: left = [5,0,3], right = [8,6]
Example 2:
Input: [1,1,1,0,6,12]
Output: 4
Explanation: left = [1,1,1,0], right = [6,12]
Note:
2 <= A.length <= 300000 <= A[i] <= 10^6- It is guaranteed there is at least one way to partition
Aas described.
int partitionDisjoint(vector<int>& A)
{
map<int,int>mpMax,mpMin;//对应的索引
int t = A[];
for(int i = ; i < A.size(); i++)
{
t = max(t,A[i]);
mpMax[i] = t;
}
t = A[A.size()-];
for(int i = A.size()-; i >= ; i--)
{
t = min(t,A[i]);
mpMin[i] = t;
} for(int i = ; i < A.size(); i++)
{
if(mpMax[i-] <= mpMin[i])return i;
} }
[leetcode-915-Partition Array into Disjoint Intervals]的更多相关文章
- [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】915. Partition Array into Disjoint Intervals 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/partitio ...
- 【leetcode】915. Partition Array into Disjoint Intervals
题目如下: 解题思路:题目要求的是在数组中找到一个下标最小的index,使得index左边(包括自己)子序列的最大值小于或者等于右边序列的最小值.那么我们可以先把数组从最左边开始到数组最右边所有子序列 ...
- [Swift]LeetCode915.将分区数组分成不相交的间隔 | Partition Array into Disjoint Intervals
Given an array A, partition it into two (contiguous) subarrays left and right so that: Every element ...
- Partition Array into Disjoint Intervals LT915
Given an array A, partition it into two (contiguous) subarrays left and right so that: Every element ...
- Partition Array into Disjoint Intervals
2020-02-10 22:16:50 问题描述: 问题求解: 解法一:MultiSet O(nlog) 看了下数据规模,第一个想到的是multiset,肯定可以ac的,就直接敲了出来. public ...
- leetcode@ [352] Data Stream as Disjoint Intervals (Binary Search & TreeSet)
https://leetcode.com/problems/data-stream-as-disjoint-intervals/ Given a data stream input of non-ne ...
- [LeetCode] 352. Data Stream as Disjoint Intervals 分离区间的数据流
Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...
- LeetCode 1043. Partition Array for Maximum Sum
原题链接在这里:https://leetcode.com/problems/partition-array-for-maximum-sum/ 题目: Given an integer array A, ...
随机推荐
- Oracle特殊查询 行列倒转 分页
--查询工资最高的前三名 (分页的感觉)select * from(select * from emp order by sal desc) twhere rownum <=3--查询工资最高的 ...
- DBA手记(学习)-library cache pin
select sid,event,p1raw from v$session_wait where event like 'library cache pin%'; select sql_text fr ...
- ztz11的noip模拟赛T1:愤怒的XiaoX
链接: https://www.luogu.org/problemnew/show/U47231 思路: 这道题其实就是一道双Lazy线段树裸题 因为我们知道,当k一定时,取反偶数次最后k位等于不取反 ...
- emlog 百度熊掌号提交插件-基于Emlog6.0.1特别版美化
插件截图 插件简介 此插件在发布文章的时候自动向百度熊掌号提交,有利于百度熊掌号收录.基于Emlog6.0.1特别版美化的插件. 在百度推送插件的基础上修改制作而成与百度推送共存,解放双手,走向人生巅 ...
- C# Redis写入程序
直接贴代码,需要引用ServiceStack.Common.dll,ServiceStack.Interfaces.dll,ServiceStack.Redis.dll,ServiceStack.Te ...
- MongoDB数据库 : 管道,用户管理,副本集等
聚合(aggregate): db.集合.aggregate([{管道:{表达式}}]) db.集合.aggregate([ {管道1:{表达式1}}, {管道2:{表达式2}}, ... ...]) ...
- pgsql 变量赋值方法
1.网上一般说的方法如下: :=,赋值,比如user_id := 20; select into 赋值,比如 SELECT INTO myrec * FROM emp WHERE empname = ...
- Python3爬虫(十八) Scrapy框架(二)
对Scrapy框架(一)的补充 Infi-chu: http://www.cnblogs.com/Infi-chu/ Scrapy优点: 提供了内置的 HTTP 缓存 ,以加速本地开发 . ...
- 20155203 2016-2017-3 《Java程序设计》第三周学习总结
20155203 2016-2017-3 <Java程序设计>第三周学习总结 教材知识要点总结 第四章 文档主文档名必须与公开类名称相同.一个原始码中可以定义多个类,但是只能有一个公开类. ...
- 对Linux命令od -tc -tx1的C语言程序实现myod-优化版
导语 自编od C语言实现版名为myod 上个星期有一个初代版,链接- myod原版 这星期的课上要求实现myod-系统调用版本,要求如下 1 参考教材第十章内容 2 用Linux IO相关系统调用编 ...