Wierd runtime error


#1

This is my code:
> class Solution:

    # @param A : head node of linked list
    # @return the head node in the linked list
    def deleteDuplicates(self, A):
        head = A
        while A and A.next:
            while A.val == A.next.val:
                A.next = A.next.next
            A = A.next
        return head

this is the error I get:

Traceback (most recent call last):
  File "main.py", line 181, in 
    Z = obj.deleteDuplicates(A)
  File "/tmp/judge/solution.py", line 14, in deleteDuplicates
    while A.val == A.next.val:
AttributeError: 'NoneType' object has no attribute 'val'

anyone knows why it happens? I AM checking for None after all…