Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- LeetCode
- 릿코드 파이썬
- 상가수익률계산기
- leetcode풀기
- 파이썬알고리즘
- 코틀린기초
- python 알고리즘
- python priority queue
- 파이썬릿코드
- 파이썬 릿코드
- 알고리즘풀기
- 잇츠디모
- 릿코드 풀기
- leetcode 풀기
- 파이썬 알고리즘
- 릿코드풀이
- python Leetcode
- 알고리즘풀이
- binary search
- 릿코드
- leetcode풀이
- 파이썬릿코드풀기
- 파이썬 알고리즘 풀기
- python sorted
- 파이썬 프로그래머스
- 파이썬알고리즘풀기
- python 릿코드
- python xor
- 릿코드풀기
- python zip_longest
Archives
- Today
- Total
소프트웨어에 대한 모든 것
2433. Find The Original Array of Prefix Xor 본문
반응형
제목
문제)
2433. 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 the answer is unique.
Example 1:
Input: pref = [5,2,0,3,1]
Output: [5,7,2,3,2]
Explanation: From the array [5,7,2,3,2] we have the following:
- pref[0] = 5.
- pref[1] = 5 ^ 7 = 2.
- pref[2] = 5 ^ 7 ^ 2 = 0.
- pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3.
- pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.
Example 2:
Input: pref = [13]
Output: [13]
Explanation: We have pref[0] = arr[0] = 13.
Constraints:
- 1 <= pref.length <= 105
- 0 <= pref[i] <= 106
솔루션1)
- XOR 특성을 이해해야 함
- XOR의 교환법칙 결합법칙을 활용
class Solution:
def findArray(self, pref: List[int]) -> List[int]:
ret = [0] * len(pref)
ret[0] = pref[0]
for i in range(1, len(pref)):
ret[i] = pref[i] ^ pref[i-1]
return ret
반응형
'알고리즘 > LeetCode' 카테고리의 다른 글
1379. Find a Corresponding Node of a Binary Tree in a Clone of That Tree (2) | 2022.12.23 |
---|---|
2265. Count Nodes Equal to Average of Subtree (0) | 2022.12.23 |
2396. Strictly Palindromic Number (0) | 2022.12.23 |
1476. Subrectangle Queries (0) | 2022.12.23 |
2465. Number of Distinct Averages (0) | 2022.12.23 |
Comments