1
2
3
4
5
6
|
class Solution:
def decode(self, encoded: List[int], first: int) -> List[int]:
ans=[first]
for i in encoded:
ans.append(i^ans[-1])
return ans
|
cs |
XOR -> Exclusive OR 문제구요
학부때 배웠던 Logical circuit 생각해보시면 쉽게 풀수있는데
파이썬에서는 " ^ " operator가 XOR 입니다. 아마 다른언어에서는 power의 개념으로 쓰이는 operator죠
반응형
'python-algorithm' 카테고리의 다른 글
Leetcode 1979. Find Greatest Common Divisor of Array (0) | 2021.08.31 |
---|---|
Leetcode 1588. Sum of All Odd Length Subarrays (0) | 2021.08.31 |
Leetcode 682. Baseball Game (0) | 2021.08.30 |
Leetcode 1441 Build an Array with Stack Operations (0) | 2021.08.30 |
백준 3135 라디오 (0) | 2021.08.30 |
댓글