-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm2433.py
26 lines (19 loc) · 863 Bytes
/
m2433.py
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
# removal of the append increases runtime dramatically --> pre-defined arr len instead
class Solution:
def findArray(self, pref: List[int]) -> List[int]:
runningXOR = pref[0]
for i in range(1, len(pref)) :
# I swapped to using the same array to save memory which significantly lowered the cost making this consistently 90+%
pref[i] = runningXOR ^ pref[i]
runningXOR ^= pref[i]
return pref
# class Solution:
# def findArray(self, pref: List[int]) -> List[int]:
# output = [pref[0]]
# runningXOR = pref[0]
# # print(5 ^ 2) # finding pref[1] --> 7
# # print(5 ^ 7 ^ 0) # finding pref[0] --> 2
# for i in range(1, len(pref)) :
# output.append(runningXOR ^ pref[i])
# runningXOR ^= (runningXOR ^ pref[i])
# return output