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

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

LeetCode 2531. Make Number of Distinct Characters Equal

2023-03-31 12:28 作者:您是打尖兒還是住店呢  | 我要投稿

You are given two?0-indexed?strings?word1?and?word2.

A?move?consists of choosing two indices?i?and?j?such that?0 <= i < word1.length?and?0 <= j < word2.length?and swapping?word1[i]?with?word2[j].

Return?true?if it is possible to get the number of distinct characters in?word1?and?word2?to be equal with?exactly one?move.?Return?false?otherwise.

?

Example 1:

Input: word1 = "ac", word2 = "b"

Output: false

Explanation: Any pair of swaps would yield two distinct characters in the first string, and one in the second string.

Example 2:

Input: word1 = "abcc", word2 = "aab"

Output: true

Explanation: We swap index 2 of the first string with index 0 of the second string. The resulting strings are word1 = "abac" and word2 = "cab", which both have 3 distinct characters.

Example 3:

Input: word1 = "abcde", word2 = "fghij"

Output: true

Explanation: Both resulting strings will have 5 distinct characters, regardless of which indices we swap.

?

Constraints:

  • 1 <= word1.length, word2.length <= 105

  • word1?and?word2?consist of only lowercase English letters.

一開始想到的是用hashmap,然而。。。還是直接用數(shù)組快啊,畢竟就是常數(shù)的復(fù)雜度。

Runtime:?11 ms, faster than?67.88%?of?Java?online submissions for?Make Number of Distinct Characters Equal.

Memory Usage:?43.5 MB, less than?64.25%?of?Java?online submissions for?Make Number of Distinct Characters Equal.


LeetCode 2531. Make Number of Distinct Characters Equal的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
麟游县| 碌曲县| 台安县| 大同县| 吉安市| 怀化市| 会宁县| 贡山| 同仁县| 新营市| 武平县| 阿勒泰市| 乌拉特后旗| 桃源县| 余干县| 桐乡市| 隆尧县| 霍城县| 田林县| 额敏县| 和林格尔县| 高邑县| 瑞丽市| 西峡县| 扎赉特旗| 井陉县| 察隅县| 唐河县| 河曲县| 安龙县| 崇仁县| 巩留县| 丰都县| 肇源县| 宣威市| 阿拉善右旗| 富源县| 巴南区| 元朗区| 浦县| 深水埗区|