java.lang.Object
g2401_2500.s2486_append_characters_to_string_to_make_subsequence.Solution

public class Solution extends Object
2486 - Append Characters to String to Make Subsequence.<p>Medium</p> <p>You are given two strings <code>s</code> and <code>t</code> consisting of only lowercase English letters.</p> <p>Return <em>the minimum number of characters that need to be appended to the end of</em> <code>s</code> <em>so that</em> <code>t</code> <em>becomes a <strong>subsequence</strong> of</em> <code>s</code>.</p> <p>A <strong>subsequence</strong> is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;coaching&rdquo;, t = &ldquo;coding&rdquo;</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> Append the characters &ldquo;ding&rdquo; to the end of s so that s = &ldquo;coachingding&rdquo;. Now, t is a subsequence of s (&ldquo;<ins> <strong>co</strong> </ins>aching<ins> <strong>ding</strong> </ins>&rdquo;). It can be shown that appending any 3 characters to the end of s will never make t a subsequence.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;abcde&rdquo;, t = &ldquo;a&rdquo;</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> t is already a subsequence of s (&ldquo;<ins> <strong>a</strong> </ins>bcde&rdquo;).</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;z&rdquo;, t = &ldquo;abcde&rdquo;</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> Append the characters &ldquo;abcde&rdquo; to the end of s so that s = &ldquo;zabcde&rdquo;. Now, t is a subsequence of s (&ldquo;z<ins> <strong>abcde</strong> </ins>&rdquo;). It can be shown that appending any 4 characters to the end of s will never make t a subsequence.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length, t.length <= 10<sup>5</sup></code></li> <li><code>s</code> and <code>t</code> consist only of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • appendCharacters

      public int appendCharacters(String s, String t)