# Leetcode 392. Is Subsequence ###### tags: `Leetcode(JAVA)` 題目 : https://leetcode.com/problems/is-subsequence/ 。 想法 : 遇到同字元就往後。 時間複雜度 : O(n)。 程式碼 : (JAVA) ``` class Solution { public boolean isSubsequence(String s, String t) { int l1=s.length(), l2=t.length(), ok=0, i=0, j=0; for( ; i<l1 && j<l2 ; ){ if(s.charAt(i) == t.charAt(j)){ i++; j++; } else{ j++; } } if(i == l1) ok=1; if(ok == 0) return false; return true; } } ```
×
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