An easy thinking to analysis this problem.

  • 5

    I think this thinking way can help us to solve and understand this problem quickly.

    First,Let's begin with some tries.
    when the rock is 1(win) 2(win) 3(win) 4(lose) I think everyone can do this,then we stop and think.

    After you take rock and your friend becomes "you" think it carefully
    for example. when there are 4 rocks,after your taking ,there are three your friend begin with
    1,2,or 3
    you lose(when there are 4 rocks) = your friend win = start with(4-1),(4-2),(4-3) win

    so there must be 3 win before 1 lose

    so 4 is a group.

    in c language we just return n%4

  • 0

    Thanks for the explanation man. This is helping; I did some random programming and came up with the answer by looking at the pattern of accepted solutions, but did not persuade myself I got it. Now it's clear !

  • 0

    I am very happy that my answer can help you.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.