Skip to content

Commit

Permalink
Create: 2001-number-of-pairs-of-interchangeable-rectangles.java
Browse files Browse the repository at this point in the history
  • Loading branch information
leahjia committed May 17, 2023
1 parent 9603026 commit 96da2a2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions java/2001-number-of-pairs-of-interchangeable-rectangles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public long interchangeableRectangles(int[][] rectangles) {
Map<Double, Long> count = new HashMap<>();
for (int[] rec : rectangles) {
double key = (double) rec[0] / rec[1];
count.put(key, count.getOrDefault(key, (long) 0) + 1);
}

long res = 0;
for (long c : count.values()) {
res += c * (c - 1) / 2;
}
return res;
}
}

0 comments on commit 96da2a2

Please sign in to comment.