Skip to content

Commit 893ca77

Browse files
authored
Create count_linked_list_nodes.py
1 parent ddd2217 commit 893ca77

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

count_linked_list_nodes.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# coding: utf-8
2+
3+
class Solution:
4+
"""
5+
@param: head: the first node of linked list.
6+
@return: An integer
7+
"""
8+
def countNodes(self, head):
9+
# write your code here
10+
ret = 0
11+
while head:
12+
ret += 1
13+
head = head.next
14+
return ret
15+
16+
# naive: http://lintcode.com/zh-cn/problem/count-linked-list-nodes/

0 commit comments

Comments
 (0)