From eba02caa42f4ea4f32e43750b0aae2c7603f82ee Mon Sep 17 00:00:00 2001 From: Srihari Thyagarajan Date: Fri, 16 Aug 2024 11:10:53 +0530 Subject: [PATCH] Update logic --- Algomap/Is_Subsequence/Is_Subsequence.py | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Algomap/Is_Subsequence/Is_Subsequence.py b/Algomap/Is_Subsequence/Is_Subsequence.py index 60fc9dad..a70e6679 100644 --- a/Algomap/Is_Subsequence/Is_Subsequence.py +++ b/Algomap/Is_Subsequence/Is_Subsequence.py @@ -5,4 +5,27 @@ def isSubsequence(self, s, t): :type t: str :rtype: bool """ - \ No newline at end of file + # Step 1 + if not s: + return True + + 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) + + # # Step 2: + # if s == "": return True + # if len(s) > len(t): return False + + # j = 0 + + # for i in range(len(t)): + # if s[j] == t[i]: + # if j == len(s) - 1: + # return True + # j += 1 + # return False \ No newline at end of file