leetcode141专题

LeetCode141之环形链表(Java实现)

一、题目   二、两种解题思路及代码实现  ①龟兔赛跑解法,快指针跳两个,慢指针跳一个,若两指针遇到一样,则有环        时间复杂度:O(n)        空间复杂度:O(1) /*** 龟兔赛跑解法 ---- 李小豪* @param head* @return*/public boolean hasCycle1(ListNode head) {ListNode t

leetcode141~Linked List Cycle

Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 解决链表问题的经典做法:使用俩指针fast和slow,判断最后fast是为null还是fast==slow即可。 public class LinkedListCycle

leetcode141 环形链表通过递归算法求解(很妙的递归算法)

/**  * Definition for singly-linked list.  * struct ListNode {  *     int val;  *     ListNode *next;  *     ListNode(int x) : val(x), next(NULL) {}  * };  */ class Solution { public:     bool hasCycl