Skip to content
Rain Hu's Workspace
Go back

[LeetCode] 2486. Accept Characters to String to Make Subsequence

Rain Hu

2486. Accept Characters to String to Make Subsequence


一、題目

A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.

Example 1:

Example 2:

Example 3:

Constraints:


二、分析

三、解題

1. Two Pointer

int appendCharacters(string s, string t) {
    int i = 0, j = 0;
    for (; i < s.length(); i++) {
        if (s[i] == t[j]) j++;
        if (j == t.length()) return 0;
    }
    return t.length()-j;
}

回目錄 Catalog


Share this post on:

Previous
[LeetCode] 2487. Remove Nodes From Linked List
Next
[LeetCode] 2485. Find the Pivot Integer