Skip to content

Commit 3d1e7c0

Browse files
add 2595
1 parent 158e7f0 commit 3d1e7c0

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|-------------
11+
| 2595 |[Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2595.java) | | Easy |
1112
| 2586 |[Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2586.java) | | Easy |
1213
| 2583 |[Kth Largest Sum in a Binary Tree](https://leetcode.com/problems/kth-largest-sum-in-a-binary-tree/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2583.java) | | Medium |
1314
| 2582 |[Pass the Pillow](https://leetcode.com/problems/pass-the-pillow/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2582.java) | | Easy |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2595 {
4+
public static class Solution1 {
5+
public int[] evenOddBit(int n) {
6+
String str = Integer.toBinaryString(n);
7+
String reverse = new StringBuilder(str).reverse().toString();
8+
int even = 0;
9+
int odd = 0;
10+
for (int i = 0; i < str.length(); i++) {
11+
if (i % 2 == 0) {
12+
if (reverse.charAt(i) == '1') {
13+
even++;
14+
}
15+
} else {
16+
if (reverse.charAt(i) == '1') {
17+
odd++;
18+
}
19+
}
20+
}
21+
return new int[]{even, odd};
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy