"""
Definition of ListNode
class ListNode(object):
def __init__(self, val, next=None):
self.val = val
self.next = next
"""
class Solution:
"""
@param head: the first node of linked list.
@return: An integer
"""
def countNodes(self, head):
# write your code here
n = 0
ptr = head
while ptr != None:
n = n + 1
ptr = ptr.next
return n
Python, LintCode, 466. 链表节点计数
最新推荐文章于 2022-12-25 09:54:20 发布