Bitwise

Memo

  • Bitwise OR will never unset an already set bit. It may set some new bits. So, bitwise OR is always non-decreasing.

Basic Operations

  • AND (&): 101 & 011 = 001
  • OR (|): 101 | 011 = 111
  • XOR (^): 101 ^ 011 = 110
  • NOT (~): ~101 = 010
  • Left Shift («): 5 << 2 => 101 -> 10100 = 20
  • Right Shift (»): 5 >> 2 => 101 -> 001 = 1

XOR

  • find single number
    • ret ^= nums[i]
  • find missing number [3, 0, 1]
    • ret = i ^ nums[i]

Problems

1

1
2
3
class Solution:
  def minimumSubarrayLength(self, nums: List[int], k: int) -> int:
    pass
Get Things Done
Built with Hugo
Theme Stack designed by Jimmy