# 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; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up