---
# System prepended metadata

title: 2568. Minimum Impossible OR
tags: [Leetcode]

---

<style>
    html, body, .ui-content {
    background: #222222;
    color: #00BFFF;
}
::-webkit-scrollbar {
    width: 10px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #2BE8CF60 0%, #2B83E860 100%);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #2BE8CF95 0%, #2B83E895 100%);
}
    /* 設定 code 模板 */
    .markdown-body code,
.markdown-body tt {
    background-color: #ffffff36;
}
.markdown-body .highlight pre,
.markdown-body pre {
    color: #ddd;
    background-color: #00000036;
}
.hljs-tag {
    color: #ddd;
}
.token.operator {
  background-color: transparent;
}
   
</style>

###### tags: `Leetcode`

# 2568. Minimum Impossible OR



###### Link : https://leetcode.com/problems/minimum-impossible-or/

## 題目
求最小不能被陣列中用位運運算OR求出來的數字
## 程式碼

```cpp=
class Solution {
public:
    //答案必定為最左邊為1 右邊全為0的數字(二進制)
    //example: 100000
    int minImpossibleOR(vector<int>& nums) {
        //紀錄二的指數的出現
        vector<bool> num(log2(*max_element(nums.begin(), nums.end())) + 1, 0);
        for(auto &n : nums){
            //出現2的指數
            if(ceil(log2(n)) == floor(log2(n)))
                num[log2(n)] = true;
        }
        for(int i = 0;i < num.size();++i){//找最小沒出現的指數
            if(num[i] == false)
                return pow(2, i);
        }
        return pow(2, num.size());
    }
};
```