python-algorithm
leetcode 2433. Find The Original Array of Prefix Xor
무적김두칠
2023. 1. 27. 18:08
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/description/
Find The Original Array of Prefix Xor - LeetCode
Find The Original Array of Prefix Xor - You are given an integer array pref of size n. Find and return the array arr of size n that satisfies: * pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]. Note that ^ denotes the bitwise-xor operation. It can be proven that
leetcode.com
1
2
3
4
5
6
|
class Solution:
def findArray(self, pref: List[int]) -> List[int]:
answer = [pref[0]]
for i in range(1,len(pref)):
answer.append(pref[i]^pref[i-1])
return answer
|
cs |
XOR 의 성질을 이용한 문제입니다
A (XOR B) XOR B 는 A와 같다는 성질인데요 쉽죠?
This is a problem using the property of XOR
A (XOR B) XOR B has the same properties as A, right?
반응형