zoukankan      html  css  js  c++  java
  • 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 };
  • 相关阅读:
    git简单使用
    简单Spring和mybatis整合配置文件
    ASP.NET程序开发范例宝典
    C# DataSet和DataTable详解
    AOP
    匿名内部类
    数据库事务
    mybatis
    线程池
    单例模式
  • 原文地址:https://www.cnblogs.com/Asurudo/p/9728613.html
Copyright © 2011-2022 走看看