五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

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

LeetCode 1177. Can Make Palindrome from Substring

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

You are given a string?s?and array?queries?where?queries[i] = [lefti, righti, ki]. We may rearrange the substring?s[lefti...righti]?for each query and then choose up to?ki?of them to replace with any lowercase English letter.

If the substring is possible to be a palindrome string after the operations above, the result of the query is?true. Otherwise, the result is?false.

Return a boolean array?answer?where?answer[i]?is the result of the?ith?query?queries[i].

Note that each letter is counted individually for replacement, so if, for example?s[lefti...righti] = "aaa", and?ki?= 2, we can only replace two of the letters. Also, note that no query modifies the initial string?s.

?

Example :

Input: s = "abcda", queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]

Output: [true,false,false,true,true]

Explanation:queries[0]: substring = "d", is palidrome.?

queries[1]: substring = "bc", is not palidrome.?

queries[2]: substring = "abcd", is not palidrome after replacing only 1 character.?

queries[3]: substring = "abcd", could be changed to "abba" which is palidrome.

?Also this can be changed to "baab" first rearrange it "bacd" then replace "cd" with "ab". queries[4]: substring = "abcda", could be changed to "abcba" which is palidrome.

Example 2:

Input: s = "lyb", queries = [[0,1,0],[2,2,1]]

Output: [false,true]

?本來寫了一大串,結(jié)果沒過,原來是沒理解題意,就是說字符串的子串查詢出來的是可以調(diào)換位置的,這樣的話,只要處理字符串出線的次數(shù)即可;下面是代碼:

Constraints:

  • 1 <= s.length, queries.length <= 105

  • 0 <= lefti?<= righti?< s.length

  • 0 <= ki?<= s.length

  • s?consists of lowercase English letters.

Accepted

24,087

Submissions

63,112


Runtime:?64 ms, faster than?57.81%?of?Java?online submissions for?Can Make Palindrome from Substring.

Memory Usage:?115.1 MB, less than?12.50%?of?Java?online submissions for?Can Make Palindrome from Substring .


LeetCode 1177. Can Make Palindrome from Substring的評論 (共 條)

分享到微博請遵守國家法律
东阳市| 长子县| 宜丰县| 陆良县| 自贡市| 高邑县| 天台县| 虎林市| 满洲里市| 宁化县| 龙岩市| 宝山区| 集安市| 松阳县| 读书| 微博| 容城县| 卢龙县| 天镇县| 凉城县| 阿城市| 高台县| 于田县| 嘉定区| 唐海县| 克东县| 麦盖提县| 丹凤县| 织金县| 昌乐县| 屯门区| 黎平县| 英德市| 睢宁县| 云阳县| 京山县| 安图县| 阿鲁科尔沁旗| 东海县| 普定县| 黔东|