国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

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

LeetCode 1763. Longest Nice Substring

2023-04-09 10:15 作者:您是打尖兒還是住店呢  | 我要投稿

A string?s?is?nice?if, for every letter of the alphabet that?s?contains, it appears?both?in uppercase and lowercase. For example,?"abABB"?is nice because?'A'?and?'a'?appear, and?'B'?and?'b'?appear. However,?"abA"?is not because?'b'?appears, but?'B'?does not.

Given a string?s, return?the longest?substring?of?s?that is?nice. If there are multiple, return the substring of the?earliest?occurrence. If there are none, return an empty string.

?

Example 1:

Input: s = "YazaAay"

Output: "aAa"

Explanation: "aAa" is a nice string because 'A/a' is the only letter of the alphabet in s, and both 'A' and 'a' appear. "aAa" is the longest nice substring.

Example 2:

Input: s = "Bb"

Output: "Bb"

Explanation: "Bb" is a nice string because both 'B' and 'b' appear. The whole string is a substring.

Example 3:

Input: s = "c"

Output: ""

Explanation: There are no nice substrings.

?

Constraints:

  • 1 <= s.length <= 100

  • s?consists of uppercase and lowercase English letters.‘

  • 題目不難,就是寫的code長了一點,先是要判斷是否是nice string,用數(shù)組最快了,

  • 然后遍歷整個字符串,條件是當j-i+1沒在hashmap中,因為如果在了,說明前面已經(jīng)有這么長的字符串滿足要求了,所以就不需要判斷的,如果是nice string,就把長度跟左右端的index放到map中,然后遍歷map,找到最長的,返回即可(如果map.size>1的情況下),map如果是空的就返回空字符串即可。

Runtime:?13 ms, faster than?30.49%?of?Java?online submissions for?Longest Nice Substring.

Memory Usage:?42.6 MB, less than?30.32%?of?Java?online submissions for?Longest Nice Substring.


LeetCode 1763. Longest Nice Substring的評論 (共 條)

分享到微博請遵守國家法律
哈尔滨市| 太仆寺旗| 兰西县| 台北县| 阜新市| 楚雄市| 南岸区| 江北区| 淅川县| 衡阳市| 鸡东县| 虎林市| 桐城市| 天等县| 枝江市| 崇州市| 东安县| 武夷山市| 荥阳市| 井陉县| 张掖市| 汽车| 宜兰县| 武功县| 石阡县| 乐陵市| 顺义区| 卓尼县| 庆元县| 承德县| 崇义县| 建瓯市| 乡城县| 专栏| 从江县| 昭苏县| 阿拉善右旗| 宝山区| 尤溪县| 宜都市| 威信县|