Skip to content

2980. Check if Bitwise OR Has Trailing Zeros 👍

  • Time: $O(n)$
  • Space: $O(1)$
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
class Solution {
 public:
  bool hasTrailingZeros(vector<int>& nums) {
    int countEven = 0;

    for (const int num : nums)
      if (num % 2 == 0)
        ++countEven;

    return countEven >= 2;
  }
};
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class Solution {
  public boolean hasTrailingZeros(int[] nums) {
    int countEven = 0;

    for (final int num : nums)
      if (num % 2 == 0)
        ++countEven;

    return countEven >= 2;
  }
}
1
2
3
class Solution:
  def hasTrailingZeros(self, nums: list[int]) -> bool:
    return sum(num % 2 == 0 for num in nums) >= 2