Python simple solution


  • 6
    A
    class Solution(object):
        def isSubsequence(self, s, t):
            """
            :type s: str
            :type t: str
            :rtype: bool
            """
            if len(s) == 0:
                return True
            if len(t) == 0:
                return False 
            i, j = 0, 0
            while i < len(s) and j < len(t):
                if s[i] == t[j]:
                    i += 1
                j += 1
            return True if i == len(s) else False
    

  • 2
    D

    Your return statement can simply be return i == len(s). You also don't need those two if statements. Good solution though.


Log in to reply
 

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