1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-10 00:09:06 +01:00

problems(swift): add “1688. Count of Matches in Tournament”

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-12-09 13:01:47 +01:00
parent fba591dc92
commit 75305c4b8d
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,19 @@
class Solution {
func numberOfMatches(_ n: Int) -> Int {
var n = n
var matches = 0
while n > 1 {
if n % 2 == 0 {
matches += n >> 1;
} else {
matches += n >> 1;
n += 2;
}
n >>= 1;
}
return matches
}
}