题解 | #旅行牛#
旅行牛
https://www.nowcoder.com/practice/5d9c86c84737493e824593d86cf94efd
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) : val(x), next(nullptr) {}
* };
*/
#include <functional>
#include <unordered_map>
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @return bool布尔型
*/
bool hasCycle(ListNode* head) {
// write code here
bool map[100001]={0};
while(head)
{
if(map[head->val])
{
return true;
}
else{
map[head->val] =true;
head = head->next;
}
}
return false;
}
};

查看4道真题和解析
海康威视公司福利 1137人发布