# 915.Partition Array into Disjoint Intervals

**915. Partition Array into Disjoint Intervals**

给定一个数组 A，将其划分为两个不相交（没有公共元素）的连续子数组 left 和 right， 使得：

> left 中的每个元素都小于或等于 right 中的每个元素。 left 和 right 都是非空的。 left 要尽可能小。 在完成这样的分组后返回 left 的长度。可以保证存在这样的划分方法。

* 示例 1：

```
输入：[5,0,3,8,6]
输出：3
解释：left = [5,0,3]，right = [8,6]
```

* 示例 2：

```
输入：[1,1,1,0,6,12]
输出：4
解释：left = [1,1,1,0]，right = [6,12]
```

方法： 要解决最短left子数组的问题，即要找一个临界点，左边的数的最大值都小于右边所有的数。

1. 首先将`A[0]`设为max，将起始点设为1，然后比较右边所有的元素，如果有小于max的，则跳出循环
2. 内层循环结束，如果已经遍历结束，则说明该起始点为所求临界点。
3. 否则起始点自增，并判断起始点值是否大于max，如果是，则刷新max值为起始点值。继续循环判断。
4. 起始点到达终点后，返回-1。

```
class Solution {
public:
    int partitionDisjoint(vector<int>& A) {
        int size=A.size();
        int max;
        max = A[0];
        int start=1;
        while(start<size)
        {
            int m=1,i;
            for(i=start;i<size;i++)
                if(A[i]<max) break;
            if (i==size)
                return start;
            else
            {
                max = (A[start]> max)?A[start]:max;
                start++;
            }
        }

        return -1;

    }
};
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/915.partition_array_into_disjoint_intervals.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
