Skip to content

Commit

Permalink
[LEET-3370] add 3370
Browse files Browse the repository at this point in the history
  • Loading branch information
fishercoder1534 committed Dec 1, 2024
1 parent 07480d6 commit 6e4e51a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions paginated_contents/algorithms/4th_thousand/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
| # | Title | Solutions | Video | Difficulty | Tag
|------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|----------------------------------------------------------------------
| 3370 | [Smallest Number With All Set Bits](https://leetcode.com/problems/smallest-number-with-all-set-bits/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3370.java) | | Easy |
| 3364 | [Minimum Positive Sum Subarray](https://leetcode.com/problems/minimum-positive-sum-subarray/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3364.java) | | Easy |
| 3360 | [Stone Removal Game](https://leetcode.com/problems/stone-removal-game/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3360.java) | | Easy |
| 3354 | [Make Array Elements Equal to Zero](https://leetcode.com/problems/make-array-elements-equal-to-zero/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3354.java) | | Easy |
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/fishercoder/solutions/fourththousand/_3370.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.fishercoder.solutions.fourththousand;

public class _3370 {
public static class Solution1 {
public int smallestNumber(int n) {
for (int num = n; ; num++) {
if (allSetBits(num)) {
return num;
}
}
}

private boolean allSetBits(int num) {
String binaryStr = Integer.toBinaryString(num);
for (char c : binaryStr.toCharArray()) {
if (c != '1') {
return false;
}
}
return true;
}
}
}

0 comments on commit 6e4e51a

Please sign in to comment.