DEV Community

Nw3965
Nw3965

Posted on

Subsequence Check: Python Code

1st.

class Solution:
    def isSubsequence(self, s: str, t: str) -> bool:
        for S in range(s):
            len(S)
            for T in range(t):
                len(T) 
                if S == T:
                    return True
                else:
                    return False
Enter fullscreen mode Exit fullscreen mode

2nd with chatGPT

def isSubsequence(s: str, t: str) -> bool:
    i, j = 0, 0

    while i < len(s) and j < len(t):
        if s[i] == t[j]:
            i += 1
        j += 1

    return i == len(s)

# Example usage:
s = "abc"
t = "ahbgdc"
result = isSubsequence(s, t)
print(result)  # Output: True

Enter fullscreen mode Exit fullscreen mode

Top comments (0)