java.lang.Object
g1701_1800.s1790_check_if_one_string_swap_can_make_strings_equal.Solution

public class Solution extends Object
1790 - Check if One String Swap Can Make Strings Equal.<p>Easy</p> <p>You are given two strings <code>s1</code> and <code>s2</code> of equal length. A <strong>string swap</strong> is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices.</p> <p>Return <code>true</code> <em>if it is possible to make both strings equal by performing <strong>at most one string swap</strong> on <strong>exactly one</strong> of the strings.</em> Otherwise, return <code>false</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s1 = &ldquo;bank&rdquo;, s2 = &ldquo;kanb&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> For example, swap the first character with the last character of s2 to make &ldquo;bank&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s1 = &ldquo;attack&rdquo;, s2 = &ldquo;defend&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> It is impossible to make them equal with one string swap.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s1 = &ldquo;kelb&rdquo;, s2 = &ldquo;kelb&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> The two strings are already equal, so no string swap operation is required.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s1.length, s2.length <= 100</code></li> <li><code>s1.length == s2.length</code></li> <li><code>s1</code> and <code>s2</code> consist of only lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • areAlmostEqual

      public boolean areAlmostEqual(String s1, String s2)