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 79d4c11 commit d5332acCopy full SHA for d5332ac
Python/defuse-the-bomb.py
@@ -0,0 +1,25 @@
1
+# Time: O(n)
2
+# Space: O(1)
3
+
4
+class Solution(object):
5
+ def decrypt(self, code, k):
6
+ """
7
+ :type code: List[int]
8
+ :type k: int
9
+ :rtype: List[int]
10
11
+ result = [0]*len(code)
12
+ if k == 0:
13
+ return result
14
+ left, right = 1, k
15
+ if k < 0:
16
+ k = -k
17
+ left, right = len(code)-k, len(code)-1
18
+ total = sum(code[i] for i in xrange(left, right+1))
19
+ for i in xrange(len(code)):
20
+ result[i] = total
21
+ total -= code[left%len(code)]
22
+ total += code[(right+1)%len(code)]
23
+ left += 1
24
+ right += 1
25
0 commit comments