最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

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

LeetCode 2399. Check Distances Between Same Letters

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

You are given a?0-indexed?string?s?consisting of only lowercase English letters, where each letter in?s?appears?exactly?twice. You are also given a?0-indexed?integer array?distance?of length?26.

Each letter in the alphabet is numbered from?0?to?25?(i.e.?'a' -> 0,?'b' -> 1,?'c' -> 2, ... ,?'z' -> 25).

In a?well-spaced?string, the number of letters between the two occurrences of the?ith?letter is?distance[i]. If the?ith?letter does not appear in?s, then?distance[i]?can be?ignored.

Return?true?if?s?is a?well-spaced?string, otherwise return?false.

?

Example 1:

Input: s = "abaccb", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

Output: true

Explanation:- 'a' appears at indices 0 and 2 so it satisfies distance[0] = 1. - 'b' appears at indices 1 and 5 so it satisfies distance[1] = 3. - 'c' appears at indices 3 and 4 so it satisfies distance[2] = 0. Note that distance[3] = 5, but since 'd' does not appear in s, it can be ignored. Return true because s is a well-spaced string.

Example 2:

Input: s = "aa", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

Output: false

Explanation:- 'a' appears at indices 0 and 1 so there are zero letters between them. Because distance[0] = 1, s is not a well-spaced string.

?

Constraints:

  • 2 <= s.length <= 52

  • s?consists only of lowercase English letters.

  • Each letter appears in?s?exactly twice.

  • distance.length == 26

  • 0 <= distance[i] <= 50

  • 我怎么就這么笨呢,,,光想著去處理第一個(gè)字符串,沒想要可以結(jié)合對應(yīng)的數(shù)組去處理,如果第2次出現(xiàn),將之前的賦值為-1就不會出錯(cuò)了。。。。還是個(gè)簡單的題目。

Runtime:?1 ms, faster than?99.30%?of?Java?online submissions for?Check Distances Between Same Letters.

Memory Usage:?42.4 MB, less than?61.34%?of?Java?online submissions for?Check Distances Between Same Letters.


LeetCode 2399. Check Distances Between Same Letters的評論 (共 條)

分享到微博請遵守國家法律
观塘区| 武安市| 杂多县| 青冈县| 通江县| 岳西县| 庆安县| 马山县| 广南县| 湖南省| 温泉县| 兴文县| 织金县| 惠东县| 淳安县| 页游| 清苑县| 敦煌市| 荥经县| 信阳市| 闽侯县| 开远市| 乌恰县| 汝阳县| 历史| 临泉县| 平原县| 岳普湖县| 长治县| 永兴县| 新竹市| 汽车| 满洲里市| 昌都县| 巴林左旗| 昭通市| 安达市| 襄樊市| 安宁市| 治多县| 南丹县|