Skip to content

Commit

Permalink
update post
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-jonghoonpark committed Jul 31, 2024
1 parent c17486d commit fbdac2d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions _posts/2024-01-31-leetcode-371.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ tags:
bit operation,
int,
unbounded,
java,
Math,
Bit Manipulation,
]
date: 2024-01-31 12:00:00 +0900
---
Expand Down Expand Up @@ -97,3 +100,24 @@ python도 음수인지 양수인지 체크를 별도의 부호 비트를 사용
## 참고

bit 연산자에 대한 설명은 [FAQ: What do the operators `<<, >>, &, |, ~, and ^` do?](https://wiki.python.org/moin/BitwiseOperators)를 참고하면 좋을 것 같다.

## 자바로 다시 풀기 (240731)

```java
class Solution {
public int getSum(int a, int b) {
while (b != 0) {
int _a = (a ^ b);
int _b = ((a & b) << 1);
a = _a;
b = _b;
}

return a;
}
}
```

### TC, SC

시간 복잡도는 O(1), 공간복잡도는 O(1) 이다. 최악의 경우 b의 비트수(32)만큼 반복문이 진행된다.

0 comments on commit fbdac2d

Please sign in to comment.