python - Leetcode:提交的函数产生意外的输出
问题描述
当我提交以下解决方案时
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"
在 leetcode 中,解决方案失败了,因为它显示了输出,true
如这里所示。但是我的机器上这个测试用例的输出false
是正确的和预期的输出。我已经尝试在各种论坛上找到解决方案,并且已经尝试了leetcode这篇文章提供的所有推荐解决方案,但它也不起作用。
解决方案失败的测试用例:
"axc"
"ahbgdc"
问题可以在 leetcode 上找到
解决方案
False != 'false'
,并且每个非空字符串(包括'false'
)的计算结果为True
。
只需返回True
和False
(布尔值,如类型提示所建议的),而不是字符串。
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
推荐阅读
- angular - Inject object into dynamically created component constructor
- go - How to pass a httprouter.Handle to a Prometheus http.HandleFunc
- android - passing data from recycler adapter to activity
- apache-kafka - Flink not forwarding Kafka metrics when parallelism greater than 1
- reactjs - How to re-fetch data in react-apollo
with value from the another input component? - java - 在本地机器上运行 ignite
- google-apps-script - 如何在 Google Apps 脚本中为可用于嵌入 Google 站点的 web 应用程序创建提示
- javascript - 每隔随机秒数使用 setInterval 运行一个函数
- c# - 如何使用面向.net框架的结构图在asp.net核心中配置hangfire并解决双向依赖
- java - 为什么不考虑单击某些按钮?