---
# System prepended metadata

title: 2486. Append Characters to String to Make Subsequence
tags: [Leetcode, Two Pointers, Medium]

---

# 2486. Append Characters to String to Make Subsequence
###### tags: `Leetcode` `Medium` `Two Pointers`
Link: https://leetcode.com/problems/append-characters-to-string-to-make-subsequence/description/
## 思路
一开始以为是双序列dp 但实际上没法定义合适的dp状态转移方程
是双指针
## Code
```java=
class Solution {
    public int appendCharacters(String s, String t) {
        int p1 = 0, p2 = 0;
        int n1 = s.length(), n2 = t.length();
        for(p2=0; p2<n2; p2++){
            while(p1!=n1 && s.charAt(p1)!=t.charAt(p2)){
                p1++;
            }
            if(p1==n1) return n2-p2;
            p1++;
        }
        return 0;
    }
}
```