Merge pull request #315 from liaozd/python-opt

nums为一个list,不需要判断为空就可以做join
This commit is contained in:
wangzheng0822 2019-05-27 09:08:36 +08:00 committed by GitHub
commit 65b185b92c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -106,10 +106,7 @@ class SinglyLinkedList:
while current:
nums.append(current.data)
current = current._next
if len(nums) > 0:
return "->".join(str(num) for num in nums)
else:
return ""
return "->".join(str(num) for num in nums)
# 重写__iter__方法方便for关键字调用打印值
def __iter__(self):