1790. Check if One String Swap Can Make Strings Equal Easy
1/**
2 * [1790] Check if One String Swap Can Make Strings Equal
3 *
4 * You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices.
5 * Return true if it is possible to make both strings equal by performing at most one string swap on exactly one of the strings. Otherwise, return false.
6 *
7 * Example 1:
8 *
9 * Input: s1 = "bank", s2 = "kanb"
10 * Output: true
11 * Explanation: For example, swap the first character with the last character of s2 to make "bank".
12 *
13 * Example 2:
14 *
15 * Input: s1 = "attack", s2 = "defend"
16 * Output: false
17 * Explanation: It is impossible to make them equal with one string swap.
18 *
19 * Example 3:
20 *
21 * Input: s1 = "kelb", s2 = "kelb"
22 * Output: true
23 * Explanation: The two strings are already equal, so no string swap operation is required.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= s1.length, s2.length <= 100
29 * s1.length == s2.length
30 * s1 and s2 consist of only lowercase English letters.
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal/
36// discuss: https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn are_almost_equal(s1: String, s2: 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_1790() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.