001package algs51; // section 5.0
002import stdlib.*;
003/* ***********************************************************************
004 *  Compilation:  javac Subsequence.java
005 *  Execution:    java Subsequence s t
006 *
007 *  Determines whether string s is a subsequence of string t.
008 *
009 *************************************************************************/
010
011
012public class XSubsequence {
013        public static boolean isXSubsequence(String s, String t) {
014                int M = s.length();
015                int N = t.length();
016
017                int i = 0;
018                for (int j = 0; j < N; j++) {
019                        if (s.charAt(i) == t.charAt(j)) i++;
020                        if (i == M) return true;
021                }
022                return false;
023        }
024
025        public static void main(String[] args) {
026                String s = args[0];
027                String t = args[1];
028                StdOut.println(isXSubsequence(s, t));
029        }
030
031}