Created
January 25, 2022 02:53
-
-
Save svaza/d8a13910eb956a869ed4b328f28ec1c8 to your computer and use it in GitHub Desktop.
Divisor Game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://leetcode.com/problems/divisor-game/ | |
| public class Solution { | |
| public enum Player { Alice = 1, Bob= 2 } | |
| private const int X = 1; | |
| public bool DivisorGame(int n) { | |
| return WhoLooses(Player.Alice, n) != Player.Alice; | |
| } | |
| public Player WhoLooses(Player playerTurn, int n) | |
| { | |
| if(X > 0 && X < n) | |
| { | |
| if(playerTurn == Player.Alice) | |
| { | |
| return WhoLooses(Player.Bob, n - X); | |
| } | |
| else | |
| { | |
| return WhoLooses(Player.Alice, n - X); | |
| } | |
| } | |
| else | |
| { | |
| return playerTurn; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment