[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, ...
随机推荐
- Linux-- 目录基本操作(2)
cp 复制文件或目录 用法:cp [OPTION] SOURCE源文件 DIRECTORY目标文件,具体可以查看 man cp 以常用的参数举例 [root@hs-192-168-33-206 tom ...
- Linux 不杀进程的情况下,如何释放磁盘资源
最近项目组人员反馈一个问题:即磁盘空间满了,但是并没看到有什么文件占用空间: [root@xxxx home]# df -h Filesystem Size Used Avail Use% Mount ...
- Linux用户和权限管理
用户:资源获取标识符,资源分配,安全权限模型的核心要素之一 密码:来实现用户认证 创建用户:useradd Username 生成的属性信息 /etc/passwd 用户名:密码:占位符:UID:GU ...
- 【vue】------浅谈vue------【William】
### Vue > Vue是一个前端js框架,由尤雨溪开发,是个人项目 Vue近几年来特别的受关注,三年前的时候angularJS霸占前端JS框架市场很长时间,接着react框架横空出世,因为它 ...
- nRF52832 BLE_DFU空中升级OTA(一)安装软件(SDK14.2.0)
准备工作,需要安装好几个软件,详细的过程请参考下面的文章(http://www.cnblogs.com/iini/p/9314246.html)这里说的非常详细,而且也有工具在云盘,对于初学者非常友好 ...
- 【Mac】解决「另一个活跃的 Homebrew 进程正在进行中」问题
问题描述 在安装 tesseract 的语言包时,由于网络下载速度太慢,我按下 ctrl + z 退出了安装,当再次输入安装命令时,系统报错如下: 解决方法 使用以下命令删除 homebrew 进程锁 ...
- PTA基础编程题目集6-3简单求和 (函数题)
6-3 简单求和 (10 分) 本题要求实现一个函数,求给定的N个整数的和. 函数接口定义: int Sum(int List[],int N) 其中给定整数存放在数组List[]中,正整数N是数组元 ...
- express添加权限拦截
express通过中间件的方式添加权限拦截 示例代码如下 app.get('/logout', checkLogin); app.get('/logout', function(req, res) { ...
- 2016-2017-2 《Java程序设计》课程总结 - 20155214
2016-2017-2 <Java程序设计>课程总结 - 20155214 目录 一.每周学习总结及实验报告链接汇总 二.代码托管 给出statistic.sh的运行结果,说明本学期的代码 ...
- 20155215 2016-2017-2 《Java程序设计》第4周学习总结
20155215 2016-2017-2 <Java程序设计>第X周学习总结 教材学习内容总结 第六章 继承,避免多个类间重复定义共同行为.子类继承父类,再扩充(extends)其他行为. ...