ID: 1 Medium hash table

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.

Submit

Log in to submit a solution.

Log in

Recent Submissions

Yanru
C/C++ · 2026-06-02 15:35
Time Limit Exceeded
Yanru
C/C++ · 2026-06-02 15:34
Time Limit Exceeded
Yanru
C/C++ · 2026-06-02 15:32
Wrong Answer
Yanru
C/C++ · 2026-06-02 15:32
Wrong Answer
Yanru
C/C++ · 2026-06-02 15:30
Wrong Answer
Yanru
C/C++ · 2026-06-02 15:18
Compilation Error
singhone0515
C/C++ · 2026-06-02 03:20
Accepted
singhone0515
C/C++ · 2026-06-02 03:19
Accepted