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

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

Leetcode 2273. Find Resultant Array After Removing Anagrams

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

You are given a?0-indexed?string array?words, where?words[i]?consists of lowercase English letters.

In one operation, select any index?i?such that?0 < i < words.length?and?words[i - 1]?and?words[i]?are?anagrams, and?delete?words[i]?from?words. Keep performing this operation as long as you can select an index that satisfies the conditions.

Return?words?after performing all operations. It can be shown that selecting the indices for each operation in?any?arbitrary order will lead to the same result.

An?Anagram?is a word or phrase formed by rearranging the letters of a different word or phrase using all the original letters exactly once. For example,?"dacb"?is an anagram of?"abdc".

?

Example 1:

Input: words = ["abba","baba","bbaa","cd","cd"]

Output: ["abba","cd"]

Explanation:One of the ways we can obtain the resultant array is by using the following operations:?

- Since words[2] = "bbaa" and words[1] = "baba" are anagrams,?

we choose index 2 and delete words[2].?

?Now words = ["abba","baba","cd","cd"].?

- Since words[1] = "baba" and words[0] = "abba" are anagrams,?

we choose index 1 and delete words[1]. ?Now words = ["abba","cd","cd"]. - Since words[2] = "cd" and words[1] = "cd"?

are anagrams, we choose index 2 and delete words[2]. ?Now words = ["abba","cd"].?

We can no longer perform any operations, so ["abba","cd"] is the final answer.

Example 2:

Input: words = ["a","b","c","d","e"]

Output: ["a","b","c","d","e"]

Explanation:No two adjacent strings in words are anagrams of each other, so no operations are performed.

?

Constraints:

  • 1 <= words.length <= 100

  • 1 <= words[i].length <= 10

  • words[i]?consists of lowercase English letters.

  • 所以理解題意是多么重要啊,我以為不是相鄰的都要看是否是Anagrams呢,所以用了hashmap,其實(shí)相鄰的就可,然后char[]轉(zhuǎn)換為字符串也絆了一跤,應(yīng)該是string.value of

    而不是tostring()方法;雖然是easy題目,教訓(xùn)深刻啊。

Runtime:?2 ms, faster than?95.29%?of?Java?online submissions for?Find Resultant Array After Removing Anagrams.

Memory Usage:?43.3 MB, less than?14.24%?of?Java?online submissions for?Find Resultant Array After Removing Anagrams.


Leetcode 2273. Find Resultant Array After Removing Anagrams的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
长兴县| 遵义市| 泾源县| 娱乐| 左云县| 阜新市| 兰西县| 嵊州市| 桃源县| 玛沁县| 淮南市| 陈巴尔虎旗| 乌苏市| 岳西县| 长葛市| 连平县| 樟树市| 重庆市| 保靖县| 沂水县| 贵阳市| 青冈县| 上高县| 阿瓦提县| 金塔县| 黄骅市| 南通市| 鸡东县| 泰来县| 延庆县| 太原市| 阿城市| 府谷县| 伊吾县| 车险| 略阳县| 博白县| 岱山县| 临夏县| 屏山县| 特克斯县|