imashutosh51

Is Subsequence

Mar 13th, 2026
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. class Solution:
  2.     def isSubsequence(self, s1: str, s2: str) -> bool:
  3.         i=0
  4.         j=0
  5.         while i<len(s1) and j<len(s2):
  6.             if s1[i]==s2[j]:
  7.                 i+=1
  8.                 j+=1
  9.             else:
  10.                 j+=1
  11.         if i==len(s1):
  12.             return True
  13.         else:
  14.             return False
  15.  
  16. '''
  17. M:2 find the LCS of s1 and s2, if the LCS is s1 means s1 is the LCS of the S2 and the reason is longest LCS of s1 and s2 can the s1 only if len(s1)<=len(s2)
  18. '''
  19.        
Advertisement
Add Comment
Please, Sign In to add comment