728x90
반응형
첫번째 코드
^연산자: 연산자는 비트 단위 XOR (Exclusive OR) 연산을 수행하는 연산자
에 대해서 알고 있다면 문제 없이 풀 수 있는 문제이다!!
class Solution:
def findArray(self, pref: List[int]) -> List[int]:
answer = [0] * len(pref)
answer[0] = pref[0]
for i in range(1, len(pref)):
answer[i] = pref[i-1] ^ pref[i]
return answer
통과
링크
https://github.com/ornni/leetcode/tree/main/2433-find-the-original-array-of-prefix-xor
반응형
'코딩 테스트 > leetcode' 카테고리의 다른 글
Count Negative Numbers in a Sorted Matrix (0) | 2024.06.20 |
---|---|
Count Items Matching a Rule (0) | 2024.06.19 |
Minimum Number of Moves to Seat Everyone (0) | 2024.06.17 |
Range Sum of BST (0) | 2024.06.14 |
Search Insert Position (0) | 2024.06.13 |