python链表计数实现

class Node(object):
def init(self, val, next=None):
self.val = val
self.next = next

定义节点,变量都是指针,赋值直接self.val = val。但是这里的含义还有点不太清楚

class Solution:
def Forlength(self,head):
cur = head
count = 0
while cur:
count += 1
cur = cur.next
return count

猜你喜欢

转载自blog.csdn.net/qq_33612402/article/details/82689066
今日推荐