Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions reverse-bits/DaleSeo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// TC: O(1)
// SC: O(1)
Comment on lines +1 to +2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaleStudy 복잡도 분석이 정확해?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요! 새로운 솔루션을 잘 구현하셨네요. 시간 복잡도는 입력 크기(고정된 32비트)에 따라 O(1)로 적절히 표기하셨고, 공간 복잡도도 O(1)로 적합합니다. 가독성도 좋아서 이해하기 쉽고, 주석도 명확하게 달려 있어 좋습니다. 다만, 혹시 더 최적화하거나 다른 방법을 고려한다면, 비트 연산 대신 라이브러리 함수를 사용할 수도 있지만, 이 방식이 가장 직관적이고 효율적입니다. 앞으로도 다양한 접근법을 시도하며 연습하시면 좋겠습니다. 계속해서 좋은 코드 기대할게요!

impl Solution {
pub fn reverse_bits(n: i32) -> i32 {
let mut result = 0u32;
let mut num = n as u32;

for i in 0..32 {
// Extract the least significant bit
let bit = num & 1;
// Place it in the reversed position
result |= bit << (31 - i);
// Shift num right to process the next bit
num >>= 1;
}

result as i32
}
}