I am trying to count the numbers of nodes in a linked list when the node value is a non-negative odd, but it seems that I couldn't get the right result.
class Solution:
"""
@param head:
@return: nothing
"""
def countNodesII(self, head):
count = 0
while head.next is not None:
head = head.next
if head.val > 0 and head.val % 2 != 0:
count += 1
else:
return 0
return count
if the input is 1->3->5->null I expect to get result of 3, but my program returned 2 instead.