We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 54223c1 commit 9d27de3Copy full SHA for 9d27de3
1652. Defuse the Bomb
@@ -0,0 +1,20 @@
1
+class Solution {
2
+ public:
3
+ vector<int> decrypt(vector<int>& code, int k) {
4
+ const int n = code.size();
5
+ vector<int> ans(n);
6
+ if (k == 0)
7
+ return ans;
8
+ int sum = 0;
9
+ int start = k > 0 ? 1 : n + k;
10
+ int end = k > 0 ? k : n - 1;
11
+ for (int i = start; i <= end; ++i)
12
+ sum += code[i];
13
+ for (int i = 0; i < n; ++i) {
14
+ ans[i] = sum;
15
+ sum -= code[start++ % n];
16
+ sum += code[++end % n];
17
+ }
18
19
20
+};
0 commit comments