Dashboard
LC #292

Nim Game

Pattern · ?

Problem

You play Nim with your friend. There are n stones. You can remove 1, 2, or 3 stones. Given n, determine if you can win assuming both play optimally.

Constraints

  • 1 ≤ n ≤ 2³¹ - 1

Example

Input
n = 4
Output
false
Why
If there are 4 stones, regardless of whether you take 1, 2, or 3, your opponent can easily take the remaining stones to win.

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗