LeetCode 1 - Two Sum
source_id: LC
Time Limit: 1 s
Statement
Given an integer array $nums$ of length $n$ and a target value $k$, count the number of index pairs $(i, j)$ such that $ i< j $ and $nums[i]+ nums[j] == k$ .
Input
First line: two integers $n$ and $k$ Second line: $n$ integers $nums[0..n-1]$
$$2≤n≤2×10^5$$ $$−10^9≤nums[i],k≤10^9$$
Output
A single integer: the number of valid pairs. Ends with a newline
Samples
Input
5 6 1 5 3 3 2
Output
2
Discussion
Log in to join the discussion.
Log in
No discussion posts yet.
Recent Submissions
Yanru
C/C++ · 2026-06-02 15:35
Yanru
C/C++ · 2026-06-02 15:34
Yanru
C/C++ · 2026-06-02 15:32
Yanru
C/C++ · 2026-06-02 15:32
Yanru
C/C++ · 2026-06-02 15:30
Yanru
C/C++ · 2026-06-02 15:18
singhone0515
C/C++ · 2026-06-02 03:20
singhone0515
C/C++ · 2026-06-02 03:19