Skip to content

Latest commit

 

History

History
13 lines (13 loc) · 620 Bytes

note0969.md

File metadata and controls

13 lines (13 loc) · 620 Bytes
  • 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.
      1. Find the index of max number in the array.
      2. Record the index of max number to the result.
      3. Reverse the array from index 0 to index of max number.
      4. Reverse the array
      5. Record the index of the last number to the result.
      6. Shorten the array excluded the last number which is the max of the array, repeat from step 1.
  • Complexity:
    • Time: O(n^2)
    • Space: O(n)