LeetCode (Linked List Cycle II)
来源:互联网 发布:淘宝贷款还不起怎么办 编辑:程序博客网 时间:2024/06/03 14:17
Problem:
Given a linked list, return the node where the cycle begins. If there is no cycle, return null
.
Solution:
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *detectCycle(ListNode *head) { unordered_map<ListNode*, int> map; while(head && map.find(head) == map.end()){ map[head]; head = head->next; } return head; }};
阅读全文
0 0
- 【LeetCode】 Linked List Cycle II
- Leetcode: Linked List Cycle II
- <Leetcode>Linked List Cycle II
- [LeetCode] Linked List Cycle II
- Leetcode: Linked List Cycle II
- LeetCode:Linked List Cycle II
- Leetcode Linked List Cycle II
- [LeetCode]Linked List Cycle II
- leetcode Linked List Cycle II
- LeetCode | Linked List Cycle II
- Leetcode: Linked List Cycle II
- [LeetCode] - Linked List Cycle II
- Leetcode: Linked List Cycle II
- LeetCode - Linked List Cycle II
- leetcode Linked List Cycle II
- Linked List Cycle II -- LeetCode
- LeetCode Linked List Cycle II
- [LeetCode] Linked List Cycle II
- 方法
- 深入理解ext4文件系统
- Jedis使用总结(8)
- 慕客网学习总结:MySQL数据库的运算符与函数
- html日常学习小结
- LeetCode (Linked List Cycle II)
- 如何创建一个HBuilder项目
- JedisCluster实现redis的keys命令的方法(9)
- IP协议
- Socket编程中select函数用法详解
- Stanford NER学习笔记
- 华为上机编程之计算字符串最后一个单词的长度,单词以空格隔开
- 类名.class 类名.this 详解
- C编程(三)流程控制之选择