2531. Make Number of Distinct Characters Equal Medium
1/**
2 * [2531] Make Number of Distinct Characters Equal
3 *
4 * You are given two 0-indexed strings word1 and word2.
5 * 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].
6 * 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.
7 *
8 * <strong class="example">Example 1:
9 *
10 * Input: word1 = "ac", word2 = "b"
11 * Output: false
12 * Explanation: Any pair of swaps would yield two distinct characters in the first string, and one in the second string.
13 *
14 * <strong class="example">Example 2:
15 *
16 * Input: word1 = "abcc", word2 = "aab"
17 * Output: true
18 * 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.
19 *
20 * <strong class="example">Example 3:
21 *
22 * Input: word1 = "abcde", word2 = "fghij"
23 * Output: true
24 * Explanation: Both resulting strings will have 5 distinct characters, regardless of which indices we swap.
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= word1.length, word2.length <= 10^5
30 * word1 and word2 consist of only lowercase English letters.
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/make-number-of-distinct-characters-equal/
36// discuss: https://leetcode.com/problems/make-number-of-distinct-characters-equal/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn is_it_possible(word1: String, word2: String) -> bool {
42 false
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_2531() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.