JAVA Easy Solution Beat 86%


  • 0
    J
    public class Solution {
        public boolean isSubsequence(String s, String t) {
            if ((s == null || s.length() == 0 ) && t != null) return true;
            if ((s == null || s.length() == 0) && (t == null || t.length() == 0)) return true;
            int len1 = s.length(), len2 = t.length();
            for (int i = 0; i < len1; i++) {
                String temp = s.substring(i, i + 1);
                if (t.contains(temp)) {
                    t = t.substring(t.indexOf(temp) + 1, t.length());
                } else {
                    return false;
                }
            }
            
            return true;
        }
    }

  • 0
    Y
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.