Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d45cafc

Browse files
Find the Duplicate Number
1 parent be5881a commit d45cafc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Link: https://leetcode.com/problems/find-the-duplicate-number/
2+
Language: C#
3+
4+
5+
6+
7+
8+
9+
public class Solution {
10+
public int FindDuplicate(int[] nums)
11+
{
12+
bool[] freq = new bool[nums.Length + 1];
13+
14+
for (int i = 0; i < nums.Length; i++)
15+
{
16+
if (freq[nums[i]] is false)
17+
freq[nums[i]] = true;
18+
else
19+
return nums[i];
20+
}
21+
22+
return -1;
23+
}
24+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /