Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e8d3f1e

Browse files
solves complement of base 10 number
1 parent 655653b commit e8d3f1e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
| 999 | [Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook) | Easy | |
263263
| 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters) | Easy | |
264264
| 1005 | [Maximize Sum of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations) | Easy | |
265-
| 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | Easy | |
265+
| 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberComplement.java) |
266266
| 1010 | [Pairs of Songs With Total Durations Divisible by 60](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60) | Easy | |
267267
| 1013 | [Partition Array into Three Parts with equal Sum](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum) | Easy | |
268268
| 1018 | [Binary Prefix Divisible by 5](https://leetcode.com/problems/binary-prefix-divisible-by-5) | Easy | |

src/ComplementOfBase10Integer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import java.util.Scanner;
2+
3+
public class ComplementOfBase10Integer {
4+
public static int bitwiseComplement(int n) {
5+
int numberOfBits = (int) (Math.floor(Math.log(n) / Math.log(2))) + 1;
6+
return ((1 << numberOfBits) - 1) ^ n;
7+
}
8+
}

0 commit comments

Comments
 (0)