Python 94%, Easy to Understand. Optimize the brutal force method
Approach\n Describe your approach to solving the problem. \nStart with brutal force. Iterate from 1 to nums[i] for each number to find if there is a number that
# Approach\n<!-- Describe your approach to solving the problem. -->\nStart with brutal force. Iterate from 1 to nums[i] for each number to find if there is a number that satisfy the requirement. \nThen, after some thinking, I optimize the starting point from 1 to n = 2**(cnt-1)-2. Where cnt is the index of the leading "1" of nums[i] in binary. \n# Code\n```python []\nclass Solution(object):\n    def minBitwiseArray(self, nums):\n        ans = [-1]*len(nums)\n        for i in range(len(nums)):\n            n = nums[i]\n            cnt = 0\n            while n != 0:\n                cnt += 1\n                n = n >> 1\n            n = 2**(cnt-1)-2\n            while n < nums[i]:\n                if n | n+1 == nums[i]:\n                    ans[i] = n\n                    break\n                n+=1\n        return ans\n        \n```
['Python']