nums为一个list,不需要判断为空就可以做join

This commit is contained in:
liaozd 2019-05-22 09:27:37 +08:00
parent 3b23b938e0
commit b237d4a7ad

View File

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