31. Next Permutation

1.問題

2.想法

  • 提問

    • 題意: 得到下一個更大的排序, 但盡可能較小

  • function header, parameter

  • test input

  • 說明想法

    • 由於最大的排序是descending, 因此必須要找出從最高位起第一個ascending的位數, 並從此位數的右方中挑出大於該位數又最接近該位數的數值swap, 並且作ascending排序

  • 測試計算複雜度

3.程式碼

Last updated