1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/swift/count-of-matches-in-tournament.swift
Matej Focko 2351dfd0ee
chore: unwrap one layer
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-12-12 14:36:00 +01:00

19 lines
347 B
Swift

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
}
}