# 2568. Minimum Impossible OR ###### tags: `Leetcode` `Medium` `Bit Manipulation` Link: https://leetcode.com/problems/minimum-impossible-or/description/ ## 思路 思路参考[这里](https://leetcode.com/problems/minimum-impossible-or/solutions/3201897/java-c-python-pow-of-2/) 找到最小的不存在在nums里面的2的次方 因为如果1不存在 那么返回1 如果2不存在 那么返回2 如果1和2都存在 我们就可以合成1~3 如果4不存在 那么返回4 如果1,2,4都存在 我们就可以合成1~7 ... ## Code ```java= class Solution { public int minImpossibleOR(int[] nums) { Set<Integer> set = new HashSet<>(); for(int num:nums) set.add(num); int val = 1; while(set.contains(val)) val*=2; return val; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up