-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1652_Defuse_the_Bomb.cpp
39 lines (39 loc) · 973 Bytes
/
1652_Defuse_the_Bomb.cpp
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
class Solution
{
public:
vector<int> decrypt(vector<int>& code, int k)
{
int ix=0, size=code.size();
vector<int> ret(size, 0);
if (k == 0)
return ret;
else
{
for (int i = 0; i < size; i++)
{
ix = 0;
if (k > 0)
{
for (int j = i + 1; ix < k; j++)
{
if (j == size)
j = 0;
ret[i] += code[j];
ix++;
}
}
else if (k < 0)
{
for (int j = i - 1; ix > k; j--)
{
if (j < 0)
j = size - 1;
ret[i] += code[j];
ix--;
}
}
}
}
return ret;
}
};