Leetcode-915 Partition Array into Disjoint Intervals(分割数组)

 1 class Solution
 2 {
 3     public:
 4         int partitionDisjoint(vector<int>& A)
 5         {
 6             if(A.size()==2&&A[0]<=A[1])
 7                 return 1;
 8             vector<int> B(A.size(),0);
 9             
10             int Min = 10000000;
11             for(int i = A.size()-1;i >= 0;i --)
12             {
13                 if(A[i]<Min)
14                 {
15                     B[i] = A[i];
16                     Min = A[i];
17                 }
18                 else
19                     B[i] = Min;
20             }
21             
22         //    for(auto d:B)
23         //        cout << d << " ";
24         //        cout << endl;
25             int result = 0;
26             int Max = A[0];
27             for(int i = 0;i < A.size();i ++)
28             {
29                 if(Max <= B[i])
30                 {
31                     result = i;
32                     break;
33                 }
34                 if(A[i]>Max)
35                 {
36                     Max = A[i];
37                 }
38             }
39             if(result==0)
40                 result = 1;
41             return result;
42         }
43 };

 

转载于:https://www.cnblogs.com/Asurudo/p/9728613.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值