LeetCode/go/find-the-winner-of-the-circular-game.go

12 lines
147 B
Go
Raw Normal View History

package main
func findTheWinner(n int, k int) int {
winner := 0
for i := 2; i <= n; i++ {
winner = (winner + k) % i
}
return winner + 1
}