-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaily14.cpp
More file actions
55 lines (49 loc) · 1.17 KB
/
Copy pathdaily14.cpp
File metadata and controls
55 lines (49 loc) · 1.17 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
// Solution 1
class Solution {
public:
bool threeConsecutiveOdds(vector<int>& arr) {
// need 1, 2 and 3 to be odd
// if 1 is even, shift up by 1
// if 2 is even, shift up by 2
// if 3 is even, shift up by 3
if (arr.size() <= 2) return false;
auto head = int{0};
while (head + 2 < arr.size()) {
if (arr[head] % 2 == 0) {
++head;
} else if (arr[head + 1] % 2 == 0) {
head += 2;
} else if (arr[head + 2] % 2 == 0) {
head += 3;
}
else
return true;
}
return false;
}
};
auto init = []() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
return 'c';
}();
// Solution 2
class Solution {
public:
bool threeConsecutiveOdds(vector<int>& arr) {
if(arr.size()==1||arr.size()==2)
return false;
for(int i=0;i<arr.size()-2;i++)
{
if(arr[i]%2!=0)
{
if(arr[i+1]%2 !=0 && arr[i+2]%2 !=0)
{
return true;
}
}
}
return false;
}
};