LeetCode_Linked List Cycle
来源:互联网 发布:淘宝客北辰老师有几个 编辑:程序博客网 时间:2024/05/15 12:32
Given a linked list, determine if it has a cycle in it.
Follow up:
Follow up:
Can you solve it without using extra space?
/** * 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) { if (head==NULL) { return false; } ListNode *pSingleSpeed=head; ListNode *pDpubleSpeed=head; while (pSingleSpeed!=NULL&&pDpubleSpeed!=NULL) { pSingleSpeed=pSingleSpeed->next; pDpubleSpeed=pDpubleSpeed->next; if (pDpubleSpeed!=NULL) { pDpubleSpeed=pDpubleSpeed->next; } else { return false; } if (pSingleSpeed==pDpubleSpeed&&pSingleSpeed!=NULL &&pDpubleSpeed!=NULL) { return true; } } return false; }};
0 0
- leetcode_Linked List Cycle
- Leetcode_linked-list-cycle-ii
- LeetCode_Linked List Cycle
- LeetCode_Linked List_Linked List Cycle
- LeetCode_linked-list-cycle-ii
- LeetCode_Linked List_Linked List Cycle II
- Leetcode_linked-list-cycle(c++ and python version)
- LeetCode_Linked List_Remove Duplicates from Sorted List
- LeetCode_Linked List_Remove Duplicates from Sorted List II
- 328.LeetCode_Linked List_Odd Even Linked List
- leetcode Linked List Cycle & Linked List Cycle ||
- Linked List Cycle II Linked List Cycle
- 【LeetCode】Linked List Cycle
- Leetcode: Linked List Cycle
- Leetcode Linked List Cycle
- Linked List Cycle
- Linked List Cycle II
- Linked List Cycle
- Android NDK 工具链的使用方法(Standalone Toolchain)
- Michael Guo的技术博客
- ubuntu14.04 安装LNMP
- 基于MVC4+EasyUI的Web开发框架经验总结(3)- 使用Json实体类构建菜单数据
- ALSA声卡驱动中的DAPM详解之七:dapm事件机制(dapm event)
- LeetCode_Linked List Cycle
- C++模板分离编译问题
- 表,字段,值的查询(持续更新)
- servlet生命周期 & http & JSP九个内置对象
- windows下编译openssl
- NYOJ448 寻找最大数 【贪心】
- python中的单元测试
- 使用VB.net 创建简单的TTS中英文混合语音朗读
- 工作周报