Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leetcode 2568. Minimum Impossible OR #213

Open
Woodyiiiiiii opened this issue Feb 19, 2023 · 0 comments
Open

Leetcode 2568. Minimum Impossible OR #213

Woodyiiiiiii opened this issue Feb 19, 2023 · 0 comments

Comments

@Woodyiiiiiii
Copy link
Owner

Woodyiiiiiii commented Feb 19, 2023

这道周赛第三题我不该做不出啊。

这是一道思维题。我一开始直觉用二分来做,但显然,二分无法判断移动方向。

所以需要重新思考另一个方向。排序,然后思考,从bits出发思考OR的性质。发现对于每一位,只有新的bits出现才能扩大范围。比如10000110000011

还需要锻炼思维,还有放弃思路想法的果断

class Solution {
    public int minImpossibleOR(int[] nums) {
        int ans = 1;
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        while (set.contains(ans)) {
            ans <<= 1;
        }
        return ans;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant