Skip to content

Commit 68a1a48

Browse files
committed
Solution as on 27-04-2022 07:25 pm
1 parent bf98e3a commit 68a1a48

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// 1608.✅ Special Array With X Elements Greater Than or Equal X
2+
3+
class Solution
4+
{
5+
public:
6+
int specialArray(vector<int> &nums)
7+
{
8+
vector<int> v(102, 0);
9+
10+
for (const auto &n : nums)
11+
{
12+
++v[n > 100 ? 100 : n];
13+
}
14+
15+
for (int i = 100; i > 0; --i)
16+
{
17+
v[i] += v[i + 1];
18+
if (v[i] == i)
19+
return i;
20+
}
21+
return -1;
22+
}
23+
};

0 commit comments

Comments
 (0)