# Got runtime error with input {} {}

• The algorithm I used is pretty straightforward:

if len_a < len_b, b will go forward (len_b - len_a) nodes and then a and b start to go forward together until they meet together or to the tail node (return null).

but I got a runtime error which I don't know why. Any suggestions?

``````class Solution:
# @param two ListNodes
# @return the intersected ListNode
return None
delta = lenb - lena
for i in range(delta):
while True:
return None

return 0

• I've probably 1% knowledge on Python, but I see some obvious things that I want to point out. the listlen routine is a recursive routine. Do you really need to make it recursive? You can just put a simple while loop

``````def listlen(ahead):
len = 0
len = len + 1
return len
``````

I don't see the error once I change it to a while loop. As I don't know much about python, I can't comment on this change in behavior further.

The next comment is about the following line

``````delta = lenb - lena
for i in range(delta):
``````

In the above block if lena is more that lenb, delta will become -ve. In that case the line inside the for loop will never execute.

Here's how the code looks now

``````class Solution:
# @param two ListNodes
# @return the intersected ListNode
return None
delta = lenb - lena
if delta < 0: delta = 0 - delta
for i in range(delta):
while True:
return None