본문 바로가기
코딩 테스트/leetcode

Find The Original Array of Prefix Xor

by ornni 2024. 6. 18.
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/2433-find-the-original-array-of-prefix-xor at main · ornni/leetcode

Collection of LeetCode questions to ace the coding interview! - Created using [LeetHub v3](https://github.com/raphaelheinz/LeetHub-3.0) - ornni/leetcode

github.com

 

반응형

'코딩 테스트 > 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