Skip to content

Commit 6904135

Browse files
add 2001
1 parent 975035c commit 6904135

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2001|[Number of Pairs of Interchangeable Rectangles](https://leetcode.com/problems/number-of-pairs-of-interchangeable-rectangles/)|[Python3](../master/python3/_2001.py) ||Medium||
1112
|2000|[Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_2000.java) ||Easy||
1213
|1996|[The Number of Weak Characters in the Game](https://leetcode.com/problems/the-number-of-weak-characters-in-the-game/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1996.java) ||Medium||
1314
|1995|[Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1995.java) ||Easy||

python3/2001.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from fractions import *
2+
from collections import Counter
3+
4+
class Solution:
5+
#credit: https://leetcode-cn.com/u/lucifer1004/
6+
def interchangeableRectangles(self, rectangles: List[List[int]]) -> int:
7+
cnt = Counter()
8+
for w, h in rectangles:
9+
cnt[Fraction(w, h)] += 1
10+
ans = 0
11+
for value in cnt.values():
12+
ans += value * (value - 1) // 2
13+
return ans

0 commit comments

Comments
 (0)