Skip to content

Commit

Permalink
solve: reverse bits
Browse files Browse the repository at this point in the history
  • Loading branch information
wogha95 committed Nov 14, 2024
1 parent 0c2d28b commit 22f172e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions reverse-bits/wogha95.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* TC: O(1)
* n ์ˆซ์ž๋ฅผ 32์ž๋ฆฌ 2์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  ๋ฐฐ์—ด๋กœ ๋ณ€๊ฒฝํ–ˆ์„๋•Œ ์ตœ๋Œ€ ๊ธธ์ด๊ฐ€ 32์ด๋ฏ€๋กœ ์ƒ์ˆ˜ ๋ณต์žก๋„๋ฅผ ๊ฐ–๋Š”๋‹ค.
*
* SC: O(1)
*/

/**
* @param {number} n - a positive integer
* @return {number} - a positive integer
*/
var reverseBits = function (n) {
const result = n.toString(2).padStart(32, "0").split("").reverse().join("");
return parseInt(result, 2);
};

0 comments on commit 22f172e

Please sign in to comment.