以下代码用于检测给出头节点的两个链表的合并点:-
def findMergeNode(head1, head2):
def get_count(head):
current = head
while(current):
count = count + 1
current = current.next
return count
#Assuming Linked List-1 is lengthier than Linked List-2
def get_intersection_node(d,head1,head2):
current_1 = head1
current_2 = head2
for i in range(d):
current_1 = current_1.next
while(current_1 and current_2):
if(current_1 == current_2):
return current_1.data
current_1 = current_1.next
current_2 = current_1.next
count_1 = get_count(head1)
count_2 = get_count(head2)
d = abs(count_1 - count_2)
if(count_1 > count_2):
return get_intersection_node(d,head1,head2)
else:
return get_intersection_node(d,head2,head1)
return 0
尽管此代码在算法和语法上均正确无误,但在hackerrank上提交时却出现了缩进错误。我已经使用vim和python -tt
命令检查了它,但是没有看到任何制表符/空格错误。
有人可以指出此代码或hackerrank论坛的python提交文件存在任何潜在/未发现的问题吗?
确切错误:-
Sorry: IndentationError: expected an indented block (solution.py, line 123)
我的代码甚至连100行都没有。由于某种原因,它正在Hackerrank提供的代码中显示错误。