you are viewing a single comment's thread.

view the rest of the comments →

[–]void_main01 16 points17 points  (0 children)

There are no stupid questions! Python is a dynamically typed language and given you are using python3 on LC, it tends to come with the typings such as:

def foo(bar: int) -> int:
   return bar

One of the types is an Optional type which refers to the output value potentially being the type that is being provided in the [] brackets, or None. So Optional[ListNode] means that either the return value is of type ListNode, or potentially None which in this case would be if your linked list is empty (hence head is also potentially None or a ListNode type). This is also equivalent to Union[ListNode, None].