Single Number XOR and Dictionary Python Leetcode Two Solutions | Algorithm explained

preview_player
Показать описание
🔴 Question Link -

Timeline
0:00 - Intro
0:21 - Single Number Leetcode Read Question
1:07 - Map Solution Explaination
1:45 - Time and Space complexity for mapping
2:01 - Map Implementation in Leetcode
3:44 : Explain Solution for XOR
6:14 : Leetcode Implentation of XOR

✅Connect with me

🔴 Question with Example

Given a non-empty array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

Example 1:
Input: [2,2,1]
Output: 1
Рекомендации по теме
Комментарии
Автор

x = [2, 2, 3, 3, 4]

for val in x:
if x.count(val) == 1:
print (val)

jbn
Автор

You did not explain the case properly for [2, 1, 2], which is what i am curious about. I know 2, 2, 1 is very easy

sumanthzvakacharla
visit shbcf.ru