LeetCode_Study_Plan/LeetCode 75

392. Is Subsequence java

개발하는루루 2022. 10. 4. 23:16

https://leetcode.com/problems/is-subsequence/

 

class Solution {
    public boolean isSubsequence(String s, String t) {

        String[] s_lt = s.split("");
        String[] t_lt = t.split("");

        if (s.length() == 0) return true;

        int index = 0;
        for(String each_t: t_lt){
           if (index == s_lt.length) return true;
           if(s_lt[index].equals(each_t)){
               index++;
           }
        }
        if (index == s_lt.length) return true;
        return false;
    }
}