v2 time O(n) space O(1) Accepted

remember the priority of bit operators is very low. use ()