Skip to content

Commit 5c5b632

Browse files
committed
single number alernate method
1 parent 896a8a6 commit 5c5b632

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

leet code/75 leetcode/260. Single Number III.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,26 @@ def single_number(nums):
1717
data.append(i)
1818
if len(data)==2:
1919
return data
20-
20+
21+
22+
def single_number(nums):
23+
n = len(nums)
24+
result = [0, 0]
25+
index = 0
26+
27+
for i in range(n):
28+
found = False
29+
for j in range(n):
30+
if i != j and nums[i] == nums[j]:
31+
found = True
32+
break
33+
if not found:
34+
result[index] = nums[i]
35+
index += 1
36+
if index == 2:
37+
break
38+
39+
return result
2140

2241
nums = list(map(int,input('enter the numbers: ').split(',')))
2342
print(single_number(nums))

0 commit comments

Comments
 (0)