292. Nim Game
If n % 4 == 0, no matter how you act, your rival can make sure the next time you choose you still have n % 4 == 0.
s1: traverse all “1”, add the number of adjacent “0”s to the output. O(n) time.
s2: check every adjacent pairs horizontally and vertically, add 1 to the ouput if the pair is (“0”, “1”). In other words, we are checking every edge to check if it is a border. O(n) time but neater.
useful skill: map(list, zip(*grid)) = transpose(grid)
.