兄弟们 实测8030是上限 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: bool hasCycle(ListNode *head) { short num = 1; while(head != nullptr) { head = head->next; // 计算链表长度 num++; if (num > 8030) { return true; } } return false; } };
点赞

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务