题解 | #判断链表中是否有环#

判断链表中是否有环

http://www.nowcoder.com/practice/650474f313294468a4ded3ce0f7898b9

这一道题主要是设置一个标志来判断链表中的某个节点是否被重复遍历到,就可以确定是否有环了

    // write code here
    bool re = false;
    while(head)
    {
        if(head->val==-11229988)
            return true;
        head->val = -11229988;
        head = head->next;
    }
    return re;
}
全部评论

相关推荐

ResourceUtilization:我嘞个董事长
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务