You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;
}
}
这道周赛第三题我不该做不出啊。
这是一道思维题。我一开始直觉用二分来做,但显然,二分无法判断移动方向。
所以需要重新思考另一个方向。排序,然后思考,从bits出发思考OR的性质。发现对于每一位,只有新的bits出现才能扩大范围。比如
100
和001
,1000
和0011
。还需要锻炼思维,还有放弃思路想法的果断。
The text was updated successfully, but these errors were encountered: