Skip to content

Commit c5aef2a

Browse files
author
larissalages
committed
add 3th solution
1 parent a1bfbb2 commit c5aef2a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

leetcode/python/backtracking/1648_count_matches_tournament.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,14 @@ def numberOfMatches(self, n):
1616
"""
1717
There are n teams, and each match makes one team be eliminated. So to eliminated n-1 teams you need n-1 matches.
1818
"""
19-
def numberOfMatches(self, n):
19+
def numberOfMatches2(self, n):
2020
return n-1
21+
22+
# Solution 3: Just to not use recursion
23+
def numberOfMatches3(self, n):
24+
cnt = 0
25+
while (n > 1):
26+
cnt += n//2
27+
n = n//2 + n % 2
28+
29+
return cnt

0 commit comments

Comments
 (0)