Skip to content

Commit 005bed9

Browse files
solve #2980: Check if Bitwise OR Has Trailing Zeros in java
1 parent ea1fbdc commit 005bed9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@
878878
| 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values) | [![Java](assets/java.png)](src/FindMissingAndRepeatedValues.java) | |
879879
| 2970 | [Count the Number of Irremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) | [![Java](assets/java.png)](src/CountTheNumberOfIncremovableSubarraysI.java) | |
880880
| 2974 | [Minimum Number Game](https://leetcode.com/problems/minimum-number-game) | [![Java](assets/java.png)](src/MinimumNumberGame.java) | |
881-
| 2980 | [Check if Bitwise OR Has Trailing Zeros](https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros) | | |
881+
| 2980 | [Check if Bitwise OR Has Trailing Zeros](https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros) | [![Java](assets/java.png)](src/CheckIfBitwiseORHasTrailingZeros.java) | |
882882
| 2996 | [Smallest Missing Integer Greater Than Sequential Prefix Sum](https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum) | | |
883883
| 3000 | [Maximum Area of Longest Diagonal Rectangle](https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle) | | |
884884
| 3005 | [Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency) | | |
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros
2+
// T: O(N)
3+
// S: O(1)
4+
5+
public class CheckIfBitwiseORHasTrailingZeros {
6+
public boolean hasTrailingZeros(int[] array) {
7+
int evenNumbers = 0;
8+
for (int element : array) {
9+
if (element % 2 == 0) {
10+
evenNumbers++;
11+
}
12+
if (evenNumbers == 2) {
13+
return true;
14+
}
15+
}
16+
return false;
17+
}
18+
}

0 commit comments

Comments
 (0)