Leetcode 969. Pancake Sorting
- Type: Array
- Approach:
- Everytime put the max number in the array to the end of the array list and shorten the array list not including the last value.
- Find the index of max number in the array.
- Record the index of max number to the result.
- Reverse the array from index 0 to index of max number.
- Reverse the array
- Record the index of the last number to the result.
- Shorten the array excluded the last number which is the max of the array, repeat from step 1.
- Everytime put the max number in the array to the end of the array list and shorten the array list not including the last value.
- Complexity:
- Time: O(n^2)
- Space: O(n)