-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
68 lines (67 loc) · 1.37 KB
/
Copy pathsolution.cpp
File metadata and controls
68 lines (67 loc) · 1.37 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
59
60
61
62
63
64
65
66
67
68
// 3471. Find the Largest Almost Missing Integer
// https://leetcode.com/problems/find-the-largest-almost-missing-integer/
// Easy | C++ | Accepted 2026-08-18
// Runtime 0 ms | Memory 28.7 MB
class Solution {
public:
int largestInteger(vector<int>& nums, int k) {
bool flagS = false;
bool flagE = false;
int start = nums[0];
int end = nums[nums.size()-1];
if(k==1)
{
vector<int> counts(51);
for(int i : nums)
{
counts[i]++;
}
int max = -1;
for(int i = 0; i<counts.size(); i++)
{
if(counts[i]==1)
{
max = i;
}
}
return max;
}
if(nums.size() ==k)
{
int m = 0;
for(int i : nums)
{
m = max(i, m);
}
return m;
}
if(start==end)
{
return -1;
}
for(int i = 1; i<nums.size()-1; i++)
{
if(nums[i]==start)
{
flagS = true;
}
if(nums[i]==end)
{
flagE = true;
}
if(flagE&&flagS)
{
return -1;
}
}
if(!flagS && !flagE)
{
return end > start ? end : start;
}
if(!flagS && flagE)
{
return start;
}
return end;
}
};