Class Solution
java.lang.Object
g0701_0800.s0765_couples_holding_hands.Solution
765 - Couples Holding Hands.<p>Hard</p>
<p>There are <code>n</code> couples sitting in <code>2n</code> seats arranged in a row and want to hold hands.</p>
<p>The people and seats are represented by an integer array <code>row</code> where <code>row[i]</code> is the ID of the person sitting in the <code>i<sup>th</sup></code> seat. The couples are numbered in order, the first couple being <code>(0, 1)</code>, the second couple being <code>(2, 3)</code>, and so on with the last couple being <code>(2n - 2, 2n - 1)</code>.</p>
<p>Return <em>the minimum number of swaps so that every couple is sitting side by side</em>. A swap consists of choosing any two people, then they stand up and switch seats.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> row = [0,2,1,3]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> We only need to swap the second (row[1]) and third (row[2]) person.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> row = [3,2,0,1]</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> All couples are already seated side by side.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2n == row.length</code></li>
<li><code>2 <= n <= 30</code></li>
<li><code>n</code> is even.</li>
<li><code>0 <= row[i] < 2n</code></li>
<li>All the elements of <code>row</code> are <strong>unique</strong>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minSwapsCouples
public int minSwapsCouples(int[] row)
-