我在leetcode上面刷一个比较简单的题目,但是出现了这样的问题让我一直解决不了。
#define MAX 100
class Solution {
public:
bool hasCycle(ListNode *head) {
int tag[MAX] = {0},i=0;
ListNode* top = head;
if(head == NULL) return false;
else{
while(top &&tag[i++] == 0)top = top->next;
if(top == nullptr)
return false;
else
return true;
}
}
private:
struct ListNode{
int val;
ListNode *next;
ListNode(int x) : val(x),next(NULL) {}
};
};
错误显示 :
solution.cpp: In member function hasCycle
Line 15: Char 25: error: cannot convert 'ListNode*' to 'Solution::ListNode*' in initialization
ListNode* top = head;
^~~~
之前我都是这么使用的,而且编译都过了 请大神解决一下我的困惑。