2980. Check if Bitwise OR Has Trailing Zeros
EasyView on LeetCode
Time: O(n)
Space: O(1)
Problem Overview
Check if grid has unique values within each column and row.
Intuition
Check if grid has unique values within each column and row. Verify all grid entries are distinct in same row/col.
Algorithm
- 1For each row: check distinct. For each column: check distinct.
Common Pitfalls
- •Simple distinct check per row and per column. HashSet per row/column.
2980.cs
C#
// Approach: At least two even numbers (bit 0 = 0) must exist for their OR to have trailing zero.
// Time: O(n) Space: O(1)
public class Solution
{
public bool HasTrailingZeros(int[] nums)
{
int cntEven = 0;
foreach (int num in nums)
{
if (num % 2 == 0)
cntEven++;
}
return cntEven >= 2;
}
}Was this solution helpful?
Related Problems
- 4. Median of Two Sorted Arrays(Hard)
- 11. Container With Most Water(Medium)
- 15. 3Sum(Medium)
- 16. 3Sum Closest(Medium)
- 26. Remove Duplicates from Sorted Array(Easy)
- 27. Remove Element(Easy)