2980. Check if Bitwise OR Has Trailing Zeros Easy
1/**
2 * [2980] Check if Bitwise OR Has Trailing Zeros
3 *
4 * You are given an array of positive integers nums.
5 * You have to check if it is possible to select two or more elements in the array such that the bitwise OR of the selected elements has at least one trailing zero in its binary representation.
6 * For example, the binary representation of 5, which is "101", does not have any trailing zeros, whereas the binary representation of 4, which is "100", has two trailing zeros.
7 * Return true if it is possible to select two or more elements whose bitwise OR has trailing zeros, return false otherwise.
8 *
9 * <strong class="example">Example 1:
10 *
11 * Input: nums = [1,2,3,4,5]
12 * Output: true
13 * Explanation: If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation "110" with one trailing zero.
14 *
15 * <strong class="example">Example 2:
16 *
17 * Input: nums = [2,4,8,16]
18 * Output: true
19 * Explanation: If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation "110" with one trailing zero.
20 * Other possible ways to select elements to have trailing zeroes in the binary representation of their bitwise OR are: (2, 8), (2, 16), (4, 8), (4, 16), (8, 16), (2, 4, 8), (2, 4, 16), (2, 8, 16), (4, 8, 16), and (2, 4, 8, 16).
21 *
22 * <strong class="example">Example 3:
23 *
24 * Input: nums = [1,3,5,7,9]
25 * Output: false
26 * Explanation: There is no possible way to select two or more elements to have trailing zeros in the binary representation of their bitwise OR.
27 *
28 *
29 * Constraints:
30 *
31 * 2 <= nums.length <= 100
32 * 1 <= nums[i] <= 100
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros/
38// discuss: https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn has_trailing_zeros(nums: Vec<i32>) -> bool {
44 false
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_2980() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.