给一个数组,要求你尽可能多的切割这个数组,使得每一个小段分别sort之后,整个数组就sort了
if minValue of Latter chunk is larger than the max value of former chunk, there can be a slice.
traverse the array from end to beginning
class Solution {
public int getChunks (int[] nums) {
List<Integer> list = new ArrayList<>();
if (nums == null || nums.length == 0) {
return -1;
}
int min = nums[nums.length - 1];
for (int i = nums.length - 1; i >= 0; i--) {
if (nums[i] > min) {
continue;
}
list.add(i + 1);
min = nums[i];
} // end of for
return list.size() + 1;
}
}