LeetCode141. Linked List Cycle
来源:互联网 发布:5s是否支持4g网络 编辑:程序博客网 时间:2024/09/21 08:57
description:
Given a linked list, determine if it has a cycle in it.
解题思路:
这一道题目主要是使用快慢指针的方式进行处理。
其中要判断快指针的point 和 next是否为null,是为了避免空指针异常。
这一题目没有bugfree,就是因为空指针异常。
/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public boolean hasCycle(ListNode head) { if (head == null || head.next == null) { return false; } ListNode slow = head; ListNode fast = head.next; while (fast != slow) { if (fast == null || fast.next == null) { return false; } fast = fast.next.next; slow = slow.next; } return true; }}
0 0
- LeetCode141:Linked List Cycle
- leetcode141. Linked List Cycle
- leetcode141: Linked List Cycle
- leetcode141 Linked List Cycle
- LeetCode141. Linked List Cycle
- leetcode141. Linked List Cycle
- leetcode141~Linked List Cycle
- LeetCode141. Linked List Cycle
- leetcode141. Linked List Cycle
- Leetcode141. Linked List Cycle
- Leetcode141. Linked List Cycle
- leetcode141. Linked List Cycle
- LeetCode141. Linked List Cycle
- Leetcode141. Linked List Cycle
- Leetcode141. Linked List Cycle
- LeetCode141—Linked List Cycle
- LeetCode141之Linked List Cycle java题解
- Leetcode141 - Linked List Cycle(链表)
- method Swizzling实践
- Java进阶之内存模型&并发编程
- GC日志分析
- leetcode:46. Permutations 排列
- 《80x86汇编语言程序设计教程》习题2.45和2.46
- LeetCode141. Linked List Cycle
- 在一个千万级的数据库查寻中,如何提高查询效率?
- Win系统svchost进程流量偷跑,如何永久杜绝?
- android:configChanges="keyboardHidden|orientation" 无效
- R语言ggplot2饼状图
- 文章标题:Android常见控件ImageView的使用方法
- ViewPager实现自动轮播效果
- 安卓Android自定义控件之自定义时钟
- SAX与DOM