leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 659dacbd46c522ad0a0f54cc27a793197dd7c7ef |
parent | f38555de9785165ad62c287062e6d11d41e43ca1 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Mon, 18 Nov 2024 16:17:31 +0100 |
Daily Problem
Diffstat:A | Problems/1652.cpp | | | ++++++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/Problems/1652.cpp b/Problems/1652.cpp
@@ -0,0 +1,22 @@
class Solution {
public:
vector<int> decrypt(vector<int> &code, int k) {
const int n = size(code);
vector<int> res(n, 0);
if (k == 0) return res;
auto [start, end] = k >= 0 ? tuple(1, k) : tuple(n + k, n - 1);
int sum = 0;
for (int i = start; i <= end; i++)
sum += code[i];
for (int i = 0; i < n; i++) {
res[i] = sum;
sum -= code[start++ % n];
sum += code[++end % n];
}
return res;
}
};
diff --git a/README.md b/README.md
@@ -1008,6 +1008,7 @@ reference and a base for solving problems.
| 1642 | Medium | [Furthest Building You Can Reach](Problems/1642.cpp) |
| 1646 | Easy | [Get Maximum in Generated Array](Problems/1646.cpp) |
| 1647 | Medium | [Minimum Deletions to Make Character Frequencies Unique](Problems/1647.cpp) |
| 1652 | Easy | [Defuse the Bomb](Problems/1652.cpp) |
| 1653 | Medium | [Minimum Deletions to Make String Balanced](Problems/1653.cpp) |
| 1657 | Medium | [Determine if Two Strings Are Close](Problems/1657.cpp) |
| 1658 | Medium | [Minimum Operations to Reduce X to Zero](Problems/1658.cpp) |