Skip to content

Commit

Permalink
Feat: 190. Reverse Bits
Browse files Browse the repository at this point in the history
  • Loading branch information
HC-kang committed Nov 13, 2024
1 parent 76fb734 commit 4af9c25
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions reverse-bits/HC-kang.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* https://leetcode.com/problems/reverse-bits
* T.C. O(1)
* S.C. O(1)
*/
function reverseBits(n: number): number {
let result = 0;
for (let i = 0; i < 32; i++) {
result = (result << 1) | (n & 1);
n >>= 1;
}
return result >>> 0;
}

0 comments on commit 4af9c25

Please sign in to comment.