无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Leetcode 2381. Shifting Letters II

2023-03-17 12:03 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a string?s?of lowercase English letters and a 2D integer array?shifts?where?shifts[i] = [starti, endi, directioni].?

For every?i,?shift?the characters in?s?from the index?starti?to the index?endi

?(inclusive) forward if?directioni?= 1,?

or shift the characters backward if?directioni?= 0.

Shifting a character?forward?means replacing it with the?next?letter in the alphabet

(wrapping around so that?'z'?becomes?'a').?

Similarly, shifting a character?backward?means replacing it with the?previous?letter in the alphabet (wrapping around so that?'a'?becomes?'z').

Return?the final string after all such shifts to?s?are applied.

?

Example 1:

Input: s = "abc", shifts = [[0,1,0],[1,2,1],[0,2,1]]

Output: "ace"

Explanation: Firstly, shift the characters from index 0 to index 1 backward.?

Now s = "zac". Secondly, shift the characters from index 1 to index 2 forward.?

Now s = "zbd". Finally, shift the characters from index 0 to index 2 forward. Now s = "ace".

Example 2:

Input: s = "dztz", shifts = [[0,0,0],[1,1,1]]

Output: "catz"

Explanation: Firstly, shift the characters from index 0 to index 0 backward.?

Now s = "cztz". Finally, shift the characters from index 1 to index 1 forward.?

Now s = "catz".

?

Constraints:

  • 1 <= s.length, shifts.length <= 5 * 104

  • shifts[i].length == 3

  • 0 <= starti?<= endi?< s.length

  • 0 <= directioni?<= 1

  • s?consists of lowercase English letters.

  • 印象深刻的一道題啊,就是將更改from -to的位置記下來,向前則from++,to--(to--一直沒想明白,--就是抵消前面++的次數(shù)),然后一個變量累加,類似于前綴和,然后去遍歷,

  • 中間出過一次問題,就是對數(shù)據(jù)%26之后還要加26再%26,就是避免溢出錯誤(還是別的負(fù)數(shù)的錯誤)我理解的是負(fù)數(shù)的錯誤。

Runtime:?10 ms, faster than?34.15%?of?Java?online submissions for?Shifting Letters II.

Memory Usage:?83.4 MB, less than?34.15%?of?Java?online submissions for?Shifting Letters II.


Leetcode 2381. Shifting Letters II的評論 (共 條)

分享到微博請遵守國家法律
隆安县| 静安区| 曲周县| 正安县| 南康市| 盐城市| 青浦区| 黑河市| 闸北区| 昭觉县| 玉溪市| 遂溪县| 苍山县| 嘉荫县| 积石山| 永德县| 丹江口市| 潜山县| 故城县| 琼中| 南溪县| 民县| 神池县| 基隆市| 丹棱县| 濉溪县| 沧源| 防城港市| 霍邱县| 昌吉市| 南丰县| 瓦房店市| 六盘水市| 凌源市| 雷波县| 千阳县| 镇赉县| 新邵县| 西藏| 裕民县| 高邮市|