c ++ – LeetCode 234. Palindrome Linked List, a strange case TLE

Here is my AC submission. And I found strange circumstances when I delete this line dumyHead-> next = NULL; my bid will give a TLE.

I know if I do not put it NO this will cause a loop reference, but I use len as a counter to browse the list, so when len <= 0 the loop will stop. I run in my local env it stopped, but in the code leet it is TLE.

I use the function "Run Code" in LeetCode, so there is only one case. My test case is [1,2,1]

So, how does this happen? Is it published for the compiler? My local env is macOS, use g ++ (detail at the end of this question).

My complete code

/ **
* Definition for simple link list.
* struct ListNode {
* int val;
* ListNode * next;
* ListNode (int x): val (x), next (NULL) {}
*};
* /
class Solution {
public:
bool isPalindrome (ListNode * head) {
if (head == NULL) {
return true;
}
int len ​​= 1;
ListNode * check = head-> next;
while (check! = NULL) {
check = check-> next;
len ++;
}
check = head-> next;
ListNode * prev = head;
for (int i = 0; i < len / 2; i++) {
            prev = check;
            check = check->following;
}
// reverse
ListNode * dumyHead = prev;
ListNode * tmp = NULL;
while (check! = NULL) {
tmp = check-> next;
check-> next = prev;
prev = check;
check = tmp;
}
// comment on this line will cause TLE
dumyHead-> next = NULL;

len / = 2;
while (len> 0) {
if (prev-> val! = head-> val) {
returns false;
}
prev = prev-> next;
head = head-> next;
len--;
}
return true;
}
};

My local env is macOS 10.14.1
g ++ version:

Configured with: --prefix = / Library / Developer / CommandLineTools / usr --with-gxx-include-dir = / usr / include / c ++ / 4.2.1
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.2.0
Thread pattern: posix
Install_dir: / Library / Developer / CommandLineTools / usr / bin