Class Solution

java.lang.Object
g0301_0400.s0389_find_the_difference.Solution

public class Solution extends Object
389 - Find the Difference.<p>Easy</p> <p>You are given two strings <code>s</code> and <code>t</code>.</p> <p>String <code>t</code> is generated by random shuffling string <code>s</code> and then add one more letter at a random position.</p> <p>Return the letter that was added to <code>t</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;abcd&rdquo;, t = &ldquo;abcde&rdquo;</p> <p><strong>Output:</strong> &ldquo;e&rdquo;</p> <p><strong>Explanation:</strong> &lsquo;e&rsquo; is the letter that was added.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &quot;&quot;, t = &ldquo;y&rdquo;</p> <p><strong>Output:</strong> &ldquo;y&rdquo;</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;a&rdquo;, t = &ldquo;aa&rdquo;</p> <p><strong>Output:</strong> &ldquo;a&rdquo;</p> <p><strong>Example 4:</strong></p> <p><strong>Input:</strong> s = &ldquo;ae&rdquo;, t = &ldquo;aea&rdquo;</p> <p><strong>Output:</strong> &ldquo;a&rdquo;</p> <p><strong>Constraints:</strong></p> <ul> <li><code>0 <= s.length <= 1000</code></li> <li><code>t.length == s.length + 1</code></li> <li><code>s</code> and <code>t</code> consist of lower-case English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • findTheDifference

      public char findTheDifference(String s, String t)