Pick up stones
2022年5月1日小于 1 分钟
Pick up stones
Question
There is a pile of n
(n > 0) stones.
Player A and Player B take turns to pick 1 or 2 stones from the pile. A starts first.
Who picks the last stone loses the game.
Now here is the question, is there a winning strategy for A or B ? If so, returns the player name. If there is none, return null.
winningStonePicking(1)
// 'B'
winningStonePicking(2)
// 'A'
winningStonePicking(3)
// 'A'
winningStonePicking(4)
// 'B'
Code
/**
* @param {number} n
* @return {'A' | 'B' | null}
*/
function canWinStonePicking(n) {
// your code here
}