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

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
陆良县| 临沂市| 克山县| 瑞金市| 普格县| 西安市| 襄樊市| 惠州市| 孟州市| 施秉县| 屏山县| 临清市| 龙岩市| 芜湖县| 通州市| 松阳县| 灯塔市| 贵州省| 黑龙江省| 谢通门县| 临漳县| 新宾| 平昌县| 邳州市| 双桥区| 托克托县| 墨江| 准格尔旗| 大埔县| 凤冈县| 伊宁市| 澄迈县| 迁西县| 新蔡县| 华蓥市| 濮阳市| 常宁市| 桐柏县| 霍城县| 渝北区| 明水县|