Skip to content

Commit 649978e

Browse files
authored
Create Number of Pairs of Interchangeable Rectangles.java
1 parent 317cdc8 commit 649978e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public long interchangeableRectangles(int[][] rectangles) {
3+
return Arrays.stream(rectangles)
4+
.collect(Collectors.groupingBy(
5+
e -> ((double) e[0]) / e[1], HashMap::new, Collectors.counting()))
6+
.values()
7+
.stream()
8+
.map(v -> (v * (v - 1)) / 2)
9+
.reduce(0L, Long::sum);
10+
}
11+
}

0 commit comments

Comments
 (0)