標籤:nat not 遞增 交換 follow 不用 lan 暴力 guarantee
[抄題]:
We have two integer sequences A and B of the same non-zero length.
We are allowed to swap elements A[i] and B[i]. Note that both elements are in the same index position in their respective sequences.
At the end of some number of swaps, A and B are both strictly increasing. (A sequence is strictly increasing if and only if A[0] < A[1] < A[2] < ... < A[A.length - 1].)
Given A and B, return the minimum number of swaps to make both sequences strictly increasing. It is guaranteed that the given input always makes it possible.
Example:Input: A = [1,3,5,4], B = [1,2,3,7]Output: 1Explanation: Swap A[3] and B[3]. Then the sequences are:A = [1, 3, 5, 7] and B = [1, 2, 3, 4]which are both strictly increasing.
[暴力解法]:
時間分析:
空間分析:
[最佳化後]:
時間分析:
空間分析:
[奇葩輸出條件]:
[奇葩corner case]:
[思維問題]:
對dp很恐懼,不知道交換以後應該怎麼檢查
[英文資料結構或演算法,為什麼不用別的資料結構或演算法]:
[一句話思路]:
[輸入量]:空: 正常情況:特大:特小:程式裡處理到的特殊情況:異常情況(不合法不合理的輸入):
[畫圖]:
[一刷]:
[二刷]:
[三刷]:
[四刷]:
[五刷]:
[五分鐘肉眼debug的結果]:
[總結]:
[複雜度]:Time complexity: O() Space complexity: O()
[演算法思想:遞迴/分治/貪心]:
[關鍵模板化代碼]:
[其他解法]:
[Follow Up]:
[LC給出的題目變變變]:
[代碼風格] :
801. Minimum Swaps To Make Sequences Increasing 為使兩個數組嚴格遞增,所需要的最小交換次數