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?
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 1137. N-th Tribonacci Number (0) | 2023.01.30 |
---|---|
leetcode 196. Delete Duplicate Emails (0) | 2023.01.29 |
leetcode 2545. Sort the Students by Their Kth Score (0) | 2023.01.27 |
leetcode 2396. Strictly Palindromic Number (0) | 2023.01.27 |
leetcode 1689. Partitioning Into Minimum Number Of Deci-Binary Numbers (0) | 2023.01.26 |
댓글