0

When I am submitting the following solution

class Solution:
def isSubsequence(self, s: str, t: str) -> bool:
    li = []
    i = 0
    for ch in t:
        if ch == s[i]:
            i+=1
            #debug
            li.append(ch)
    if s == ''.join(li):
        return "true"
    else:
        return "false"

in leetcode, solution is failing because it it shows ouput being true as can be seen here. But output for this testcase on my mahcine is false which is correct and expected ouput. I have tried finding solution for this on various forums and already tried all the recommened solution provided by this post by leetcode but it is also not working.

The test case for which solution is failing:

"axc" "ahbgdc"

Question can be found here on leetcode

1 Answer 1

2

False != 'false', and every non-empty string (including 'false') evaluates to True.

Just return True and False (bool values, like type hints suggest), not strings.

def isSubsequence(self, s: str, t: str) -> bool:
    li = []
    i = 0
    for ch in t:
        if ch == s[i]:
            i+=1
            #debug
            li.append(ch)
    if s == ''.join(li):
        return True
    else:
        return False
Sign up to request clarification or add additional context in comments.

2 Comments

In the given examples they have given return false that's why I used 'false' and 'true'. Thanks for help
The given examples are from other languages where boolean values are lowercase. See that they still don't have quotes around them - ergo they're not strings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.