Python count bits appear at least once, at least twice. Time O(n) space O(1)
Intuition\n Describe your first thoughts on how to solve this problem. \nor1, or2 hold all set bit that appear at least once, at least twice.  \nThe set bit tha
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nor1, or2 hold all set bit that appear at least once, at least twice.  \nThe set bit that only appears once is or1 & ~or2\nWe greedily shift though each element k times, calculate result and choose the max value\n\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```python\nclass Solution:\n    def maximumOr(self, nums: List[int], k: int) -> int:\n        or1,or2=0,0\n        for v in nums:\n            or2 |= or1&v\n            or1 |= v\n        or1 &=~or2\n        return max(or2|(or1 & ~v)|(v<<k) for v in nums)\n        \n```
['Python3']