Skip to content

Commit c4ab01d

Browse files
Create array_pair_sum.py
1 parent 8f4a6df commit c4ab01d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def array_pair_sum(arr,k):
2+
if len(arr) < 2:
3+
return
4+
5+
seen = set()
6+
output = set()
7+
8+
for val in arr:
9+
target = k - val
10+
11+
if target not in seen:
12+
seen.add(val)
13+
else:
14+
output.add(((min(target,val)),max(target,val)))
15+
16+
return len(output)

0 commit comments

Comments
 (0)