Skip to content

Commit fc3e12c

Browse files
solves count number of matches in tournament
1 parent 16c2825 commit fc3e12c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@
415415
| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth) | [![Java](assets/java.png)](src/RichestCustomerWealth.java) | |
416416
| 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation) | [![Java](assets/java.png)](src/GoalParserInterpretation.java) | |
417417
| 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings) | [![Java](assets/java.png)](src/CountTheNumberOfConsistentStrings.java) | |
418-
| 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament) | | |
418+
| 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament) | [![Java](assets/java.png)](src/CountOfMatchesInTournament.java) | |
419419
| 1694 | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number) | | |
420420
| 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch) | | |
421421
| 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | | |

src/CountOfMatchesInTournament.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// https://leetcode.com/problems/count-of-matches-in-tournament
2+
// T: O(log N)
3+
// S: O(log N)
4+
5+
public class CountOfMatchesInTournament {
6+
public int numberOfMatches(int n) {
7+
if (n == 1) return 0;
8+
return n / 2 + numberOfMatches(n - n / 2);
9+
}
10+
}

0 commit comments

Comments
 (0)