Two Sum Exists
Python
Medium
2 views
Problem Description
Read n integers and target T. Output YES if there exist i
Input Format
Line1 n T. Line2 n integers.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if len(p)<2: sys.exit(0)
n=int(p[0]); T=int(p[1])
a=list(map(int,p[2:2+n]))
seen=set()
ok=False
for x in a:
if (T-x) in seen:
ok=True
break
seen.add(x)
sys.stdout.write('YES' if ok else 'NO')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!