Skip to content

Commit

Permalink
add solution: Reverse Bits
Browse files Browse the repository at this point in the history
  • Loading branch information
GotPrgmer committed Jan 3, 2025
1 parent 7ead471 commit 6a053f1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions reverse-bits/Gotprgmer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// ์ฒ˜์Œ ๋ฌธ์ œ๋ฅผ ๋ดค์„๋•Œ๋Š” ์ดํ•ด๊ฐ€ ์ž˜ ๊ฐ€์ง€ ์•Š์•˜์ง€๋งŒ,
// ๋น„ํŠธ๋“ค์„ ๋’ค์ง‘์œผ๋ผ๋Š” ์„ค๋ช…์œผ๋กœ ํ’€์—ˆ๋˜ ๊ฒƒ ๊ฐ™๋‹ค.
// Integer.reverse() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ’€์—ˆ๋‹ค.
// ์ง€ํ”ผํ‹ฐ์˜ ๋„์›€์œผ๋กœ Integer.reverse()๋ฅผ ์‚ฌ์šฉํ•˜๋ผ๋Š” ํžŒํŠธ๋ฅผ ์–ป์—ˆ๋‹ค.
// ์ฐพ์•„๋ณด๋‹ˆ reverse(N)๋Š” N์„ 2์˜ ๋ณด์ˆ˜ ๋น„ํŠธ๋กœ ๋ฐ”๊พธ๊ณ  ๊ทธ๊ฒƒ์„ ๋’ค์ง‘๋Š” ๋ฐฉ์‹์ด์—ˆ๋‹ค.
// ์‹œ๊ฐ„๋ณต์žก๋„ : O(1) -> Integer๊ฐ€ 32๋น„ํŠธ ๊ณ ์ •์ด๋ผ์„œ O(1)
// ๊ณต๊ฐ„๋ณต์žก๋„ : O(1) -> 32๋น„ํŠธ ๊ณ ์ •
public class Solution {
// you need treat n as an unsigned value
public int reverseBits(int n) {
return Integer.reverse(n);
}
}

0 comments on commit 6a053f1

Please sign in to comment.