Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
We are given an array A consisting of N distinct integers.
We would like to sort array A into ascending order using a simple algorithm.
First, we divide it into one or more slices (a slice is a contiguous subarray).
Then we sort each slice. After that, we join the sorted slices in the same order.
Write a function solution that returns the maximum number of slices for which the algorithm will return a correctly sorted array.
[2,4,1], [6,5], [9,7] then after soring each slice and joining them together, the whole array will be sorted into ascending order.
A= [4,3,2,6,1] will return 1. the array cannot be split into smaller slices; it has to be sorted all at once.
N range [1..100,000]
element range [1..1,000,000,000]
Solution
4-1) if so, Assign the merged array to the given array and return the slice count as it is.
4-2) otherwise, sort the given array and return 1
Exit condition
Another solution
fullshinesun/LeetCode@bd17eaf