Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2483 from leahjia/leah
Browse files Browse the repository at this point in the history
Create: 2001-number-of-pairs-of-interchangeable-rectangles.java
  • Loading branch information
a93a authored May 17, 2023
2 parents 2c9c5a5 + 96da2a2 commit 6840ef8
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 6840ef8

Please sign in to comment.