Class Solution
java.lang.Object
g2001_2100.s2001_number_of_pairs_of_interchangeable_rectangles.Solution
2001 - Number of Pairs of Interchangeable Rectangles.<p>Medium</p>
<p>You are given <code>n</code> rectangles represented by a <strong>0-indexed</strong> 2D integer array <code>rectangles</code>, where <code>rectangles[i] = [width<sub>i</sub>, height<sub>i</sub>]</code> denotes the width and height of the <code>i<sup>th</sup></code> rectangle.</p>
<p>Two rectangles <code>i</code> and <code>j</code> (<code>i < j</code>) are considered <strong>interchangeable</strong> if they have the <strong>same</strong> width-to-height ratio. More formally, two rectangles are <strong>interchangeable</strong> if <code>width<sub>i</sub>/height<sub>i</sub> == width<sub>j</sub>/height<sub>j</sub></code> (using decimal division, not integer division).</p>
<p>Return <em>the <strong>number</strong> of pairs of <strong>interchangeable</strong> rectangles in</em> <code>rectangles</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> rectangles = [[4,8],[3,6],[10,20],[15,30]]</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong> The following are the interchangeable pairs of rectangles by index (0-indexed):</p>
<ul>
<li>
<p>Rectangle 0 with rectangle 1: 4/8 == 3/6.</p>
</li>
<li>
<p>Rectangle 0 with rectangle 2: 4/8 == 10/20.</p>
</li>
<li>
<p>Rectangle 0 with rectangle 3: 4/8 == 15/30.</p>
</li>
<li>
<p>Rectangle 1 with rectangle 2: 3/6 == 10/20.</p>
</li>
<li>
<p>Rectangle 1 with rectangle 3: 3/6 == 15/30.</p>
</li>
<li>
<p>Rectangle 2 with rectangle 3: 10/20 == 15/30.</p>
</li>
</ul>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> rectangles = [[4,5],[7,8]]</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> There are no interchangeable pairs of rectangles.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == rectangles.length</code></li>
<li><code>1 <= n <= 10<sup>5</sup></code></li>
<li><code>rectangles[i].length == 2</code></li>
<li><code>1 <= width<sub>i</sub>, height<sub>i</sub> <= 10<sup>5</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
interchangeableRectangles
public long interchangeableRectangles(int[][] rec)
-