# Why is my solution exceeding "Memory limit" ?

• I have the following simple solution implemented : but it seems to exceed memory limits for some reason , can someone take a look see whats wrong ?

``````class Solution(object):
"""
:rtype: ListNode
"""
return None
else:
count_A,count_B = 1,1
while current_A.next:
current_A = current_A.next
count_A +=1

while current_B.next:
current_B = current_B.next
count_B +=1

diff = abs(count_A - count_B)
print count_A , count_B
if count_A > count_B:
for i in xrange(diff):
current_A = current_A.next
while current_A.next and current_B.next:
if current_A == current_B:
return current_A
else:
current_A = current_A.next
current_B = current_B.next
return None
elif count_B > count_A :
for i in xrange(diff):
current_B = current_B.next
while current_A.next and current_B.next:
if current_A == current_B:
return current_A
else:
current_A = current_A.next
current_B = current_B.next
return None``````

• I get memory limit too, with code somehow like yours. But I've tried simply coping every answer in LeetCode Discuss written in Python and all those got memory limit exceeded.
Dunno why.

Updated 06/20/2016:
Wired thing happened. I first run a solution and it got memory limit.
Then I tried copying another solution. It passed! And when I used ctrl+z to get back to my first solution and tried submitting it again, it got passed too.

There must be something wrong.

• I have the same situation today, I am using Python as well.

• I have written similar code in Python, and my code also exceeds the memory limit. Can anyone spot where memory corruption may have occurred? Thanks!

``````class Solution(object):
"""
:rtype: ListNode
"""
return None
A_len = self.getListLength(curr_A)
B_len = self.getListLength(curr_B)
diff = A_len - B_len
if diff > 0:
for i in range(diff):
curr_A = curr_A.next
else:
for j in range(-diff):
curr_B = curr_B.next
while curr_A is not None and curr_B is not None:
if curr_A.val == curr_B.val:
return curr_A
else:
curr_A = curr_A.next
curr_B  = curr_B.next
return None