aman goyal
aman goyal

Reputation: 301

Leetcode : Submitted Function producing Unexpected output

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

Upvotes: 0

Views: 77

Answers (1)

h4z3
h4z3

Reputation: 5458

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

Upvotes: 2

Related Questions