Skip to content

Commit 738c3c2

Browse files
committed
leetcode 217
1 parent b68aa0b commit 738c3c2

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
7+
8+
/* ascii value
9+
A=65,Z=90,a=97,z=122
10+
*/
11+
12+
/* --------------------MAIN PROGRAM----------------------------*/
13+
// to run ctrl+b
14+
const ll INF=1e18;
15+
const ll mod1=1e9+7;
16+
const ll mod2=998244353;
17+
// Techniques :
18+
// divide into cases, brute force, pattern finding
19+
// sort, greedy, binary search, two pointer
20+
// transform into graph
21+
22+
// Experience :
23+
// Cp is nothing but only observation and mathematics.
24+
25+
26+
//Add main code here
27+
28+
class Solution
29+
{
30+
public:
31+
bool containsDuplicate(vector<int> &nums)
32+
{
33+
// approach 1
34+
// via map
35+
// map<int, int> m;
36+
// for (auto x : nums)
37+
// {
38+
// m[x]++;
39+
// if (m[x] > 1)
40+
// return true;
41+
// }
42+
// return false;
43+
44+
// approach 2
45+
// via set
46+
set<int> s;
47+
for (auto x : nums)
48+
{
49+
s.insert(x);
50+
}
51+
return s.size() != nums.size();
52+
}
53+
};
54+
55+
/* -----------------END OF PROGRAM --------------------*/
56+
/*
57+
* stuff you should look before submission
58+
* constraint and time limit
59+
* int overflow
60+
* special test case (n=0||n=1||n=2)
61+
* don't get stuck on one approach if you get wrong answer
62+
*/

0 commit comments

Comments
 (0)