观焦点:LeetCode 1652. Defuse the Bomb

2023-03-11 17:01:47 来源:哔哩哔哩

You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array codeof length of nand a key k.


(资料图片)

To decrypt the code, you must replace every number. All the numbers are replaced simultaneously.

If k > 0, replace the ithnumber with the sum of the next knumbers.

If k < 0, replace the ithnumber with the sum of the previous knumbers.

If k == 0, replace the ithnumber with 0.

As codeis circular, the next element of code[n-1]is code[0], and the previous element of code[0]is code[n-1].

Given the circular array codeand an integer key k, return the decrypted code to defuse the bomb!

Example 1:

Input: code = [5,7,1,4], k = 3

Output: [12,10,16,13]

Explanation: Each number is replaced by the sum of the next 3 numbers. The decrypted code is [7+1+4, 1+4+5, 4+5+7, 5+7+1]. Notice that the numbers wrap around.

Example 2:

Input: code = [1,2,3,4], k = 0

Output: [0,0,0,0]

Explanation: When k is zero, the numbers are replaced by 0.

Example 3:

Input: code = [2,4,9,3], k = -2

Output: [12,5,6,13]

Explanation: The decrypted code is [3+9, 2+3, 4+2, 9+4]. Notice that the numbers wrap around again. If k is negative, the sum is of the previous numbers.

Constraints:

n == code.length

1 <= n <= 100

1 <= code[i] <= 100

-(n - 1) <= k <= n - 1

easy 题目,但是写了2个函数,分别是向前的,和向后的。。

Runtime: 2 ms, faster than 39.02% of Java online submissions for Defuse the Bomb.

Memory Usage: 42.5 MB, less than 45.90% of Java online submissions for Defuse the Bomb.

标签:

观焦点:LeetCode 1652. Defuse the Bomb

Youhaveabombtodefuse,andyourtimeisrunningout!Yourinformerwillprovideyouwithacirculararraycodeoflengthofnandakeyk Todecryptthecode,you

2023-03-11 17:01:47

全球快播:Twitch在严重违规后暂停新帐户的直播

在周末流式传播“严重违反”其服务条款的内容后,Twitch暂时阻止了新创作者的直播。据Vice说,Trolls使用游戏流

2023-03-11 16:06:17

世界热推荐:绿萝叶子发黄的原因及解决方法_绿萝叶子有黑斑是什么原因

1、主要是空气太干燥、施肥太浓或者光线不适。2、绿萝喜湿润的环境,在干燥的环境下易叶片发黄、焦边等...

2023-03-11 13:14:46

今日热闻!武藤兰作品

1、武藤兰动态壁纸是一款壁纸美化类软件。2、支持Android2 1。本文到此结束,希望对大家有所帮助。

2023-03-11 10:44:17

世界实时:织女是什么生肖变的_织女是什么生肖

1、我觉得如果是单纯的织女,应该开的是兔的生肖。2、因为我们所知道的牛郎织女的故事,认为是神州侠侣。

2023-03-11 09:50:23

环球热点评!怎么关闭借呗备用金_怎么关闭借呗

1、在我的界面中,找到并点击进入。不好意思。2、找到右上角的三个点,点击进入。3、单击以在弹出窗口中...

2023-03-11 05:10:22

世界关注:山西违章查询官方网站_山西违章查询网官方网站

1、我的车牌是晋m17520。2、查询在佛山的违章。本文就为大家分享到这里,希望小伙伴们会喜欢。

2023-03-11 02:17:01

今亮点!抗逆性征

1、植物的抗逆性征是指植物具有的抵抗不利环境的某些性状;如抗寒,抗旱,抗盐,抗病虫害等。2、自然界一...

2023-03-10 16:51:11

世界最资讯丨央行阮健弘:金融业综合统计已提前完成阶段性发展目标

中国人民银行调查统计司司长阮健弘日前在《中国金融》上撰文指出,金融业综合统计是国家金融基础设施现...

2023-03-10 14:51:11

天天简讯:中国航母cg动画宣传片

1、StrengthofaThousandMen是TwoStepsFromHell公司创作专辑《Archa

2023-03-10 13:48:10
x 广告
x 广告

Copyright ©  2015-2022 西南经营网版权所有  备案号:皖ICP备2022009963号-8   联系邮箱:39 60 29 14 2@qq.com