easy C# solution


  • 0
    K
    public class Solution {
        public bool IsSubsequence(string s, string t) {
            
            if (s==null && t==null) return true;
            if (t==null) return false; 
            
            int index = 0;
            int oldindex = -1;
            char[] arr = t.ToCharArray();
    
            for (int i=0;i<s.Length;i++) {
                index = Array.IndexOf(arr,s[i],oldindex+1);
                if (index == -1) return false;
                oldindex = index;
            }
            return true;
        }
    }
    

Log in to reply
 

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