Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f0f274e

Browse files
Create 2683.py
1 parent 11fbfb1 commit f0f274e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎2501-3000/2683.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution(object):
2+
def doesValidArrayExist(self, derived):
3+
"""
4+
:type derived: List[int]
5+
:rtype: bool
6+
"""
7+
n = len(derived)
8+
xor_sum = 0
9+
10+
# Hints-02: The xor-sum of the derived array should be 0 since there is always a duplicate occurrence of each element.
11+
12+
# Example: Length of derived=4
13+
# derived[0]=org[0]^org[1]
14+
# derived[1]=org[1]^org[2]
15+
# derived[2]=org[2]^org[3]
16+
# derived[3]=org[3]^org[0]
17+
18+
# Xor-Sum = derived[0] ^ derived[1] ^ derived[2] ^ derived[3]
19+
# Xor-Sum = (org[0]^org[1]) ^ (org[1]^org[2]) ^ (org[2]^org[3]) ^ (org[3]^org[0])
20+
# #re-arrange it.....
21+
# Xor-Sum = (org[0]^org[0]) ^ (org[1]^org[1]) ^ (org[2]^org[2]) ^ (org[3]^org[3])
22+
# Xor-Sum = 0
23+
24+
for num in derived:
25+
xor_sum ^= num
26+
27+
return xor_sum == 0
28+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /