Skip to content

Latest commit

 

History

History
9 lines (9 loc) · 487 Bytes

File metadata and controls

9 lines (9 loc) · 487 Bytes
  • Type: Array (greedy)
  • Approach:
    1. Try make A[0] in a whole row, the condition is that A[i] == A[0] || B[i] == A[0], a and b are the number of swap to make a whole row A[0].
    2. Try B[0], the condition is that A[i] == B[0] || B[i] == B[0], a and b are the number of swap to make a whole row B[0].
    3. Return -1.
  • Complexity:
    • Time: O(n)
    • Space: O(1)