leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 46c20c853638151a87a1dfe92f55f8227dc2dc7c |
parent | b49f436b8aa7668c088dd74702116afd0cf37836 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Sat, 6 Apr 2024 13:04:01 +0200 |
1 Random Problem
Diffstat:A | Problems/2593.cpp | | | ++++++++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/Problems/2593.cpp b/Problems/2593.cpp
@@ -0,0 +1,24 @@
class Solution {
public:
long long findScore(const vector<int> &nums) const {
static uint8_t marked[500002];
static int indices[500002];
const int n = size(nums);
long long res = 0;
memset(marked, 0x00, sizeof(marked));
iota(begin(indices), begin(indices) + n, 0);
sort(begin(indices), begin(indices) + n,
[&nums](int a, int b) { return nums[a] != nums[b] ? nums[a] < nums[b] : a < b; });
for (int i = 0; i < n; i++) {
const int idx = indices[i];
if (marked[idx + 1]) continue;
marked[idx] = marked[idx + 1] = marked[idx + 2] = 1;
res += nums[idx];
}
return res;
}
};
diff --git a/README.md b/README.md
@@ -1119,6 +1119,7 @@ for solving problems.
| 2571 | Medium | [Minimum Operations to Reduce an Integer to 0](Problems/2571.cpp) |
| 2579 | Medium | [Count Total Number of Colored Cells](Problems/2579.cpp) |
| 2592 | Medium | [Maximize Greatness of an Array](Problems/2592.cpp) |
| 2593 | Medium | [Find Score of an Array After Marking All Elements](Problems/2593.cpp) |
| 2596 | Medium | [Check Knight Tour Configuration](Problems/2596.cpp) |
| 2606 | Medium | [Find the Substring With Maximum Cost](Problems/2606.cpp) |
| 2610 | Medium | [Convert an Array Into a 2D Array With Conditions](Problems/2610.cpp) |