-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindtheuniquenumber.cpp
More file actions
58 lines (51 loc) · 1.23 KB
/
Findtheuniquenumber.cpp
File metadata and controls
58 lines (51 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
#include <string>
#include<vector>
using namespace std;
float find_uniq(const vector<float>& v)
{
float common, unique;
if (v[0] == v[1]) {
common = v[0];
}
else if (v[0] == v[2]) {
common = v[0];
}
else {
return v[0];
}
for (float num : v) {
if (num != common) {
return num;
}
}
return -1;
}
int main()
{
cout << find_uniq({ 1, 1, 1, 2, 1, 1 });
return 0;
}
/*Description:
There is an array with some numbers. All numbers are equal except for one. Try to find it!
find_uniq(std::vector<float>{1, 1, 1, 2, 1, 1}); // --> 2
find_uniq(std::vector<float>{0, 0, 0.55, 0, 0}); // --> 0.55
It’s guaranteed that array contains at least 3 numbers.
The tests contain some very huge arrays, so think about performance.
This is the first kata in series:
Find the unique number (this kata)
Find the unique string
Find The Unique
Fundamentals
Algorithms
Arrays*/
// /> フ
// | n n 彡
// /`ミ_xノ
// / |
// / ヽ ノ
// │ | | |
// / ̄| | | |
// | ( ̄ヽ__ヽ_)__)
// \二つ
// ITS CAT FOR YOU