You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array
codeof length ofnand a keyk.To decrypt the code, you must replace every number. All the numbers are replaced simultaneously.
- If
k > 0, replace theithnumber with the sum of the nextknumbers.- If
k < 0, replace theithnumber with the sum of the previousknumbers.- If
k == 0, replace theithnumber with0.As
codeis circular, the next element ofcode[n-1]iscode[0], and the previous element ofcode[0]iscode[n-1].Given the circular array
codeand an integer keyk, return the decrypted code to defuse the bomb!
1 | class Solution { |