The 12th Week of ARTS:LinkedListCycle_141
Introduction
- Algorithm - Learning Algorithm
- Review - Learning English
- Tip - Learning Techniques
- Share - Learning Influence
Let's do it!!!
Algorithm
Sort List
-
Description
Given a linked list, determine if it has a cycle in it. -
My Solution
package com.silence.arts.leetcode.list;
/**
* <br>
* <b>Function:</b><br>
* <b>Author:</b>@author Silence<br>
* <b>Date:</b>2018-10-21 23:50<br>
* <b>Desc:</b>无<br>
*/
public class LinkedListCycle_141 {
/**
* tow points
* thinking about two runner are running on the track
* fast one will catch up the slow one if there is a cycle
* @param head
* @return
*/
public static boolean hasCycle(ListNode head) {
if (null == head || null == head.next) {
return false;
}
ListNode slow = head;
ListNode fast = head.next;
while (slow != fast) {
if (null == fast || null == fast.next) {
return false;
}
slow = slow.next;
fast = fast.next.next;
}
return true;
}
/**
* 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) {
ListNode fast = head;
ListNode slow = head;
while(slow != null && fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
if (slow == fast) {
return true;
}
}
return false;
}
}
public static void main(String[] args) {
}
}
tow points
Review
Why Do All Websites Look the Same?
As a visual designer, the author thinks that all web pages on the internet looked the same.
Today’s internet is bland. Everything looks the same: generic fonts, no layouts to speak of, interchangeable pages, and an absence of expressive visual language. Even micro-typography is a mess.
Tips
-
JS
indexOf()
- indexOf('') == 0
-
Java 序列化
- 实现 Serializable 接口,自动进行序列化;static 变量不会序列化;
- 实现 Externalizable 接口,需要手动序列化;static 变量会序列化;
-
LinkedList
底层双向链表add
时直接将最后一个节点赋值为last.next = newNode; newNode.prev = last
;get
时,根据index
与size >> 2
,大小,决定从头遍历还是从尾部遍历;
-
HashSet
- 不允许存放重复 value 的集合,底层用
HashMap
实现; add
时基于map.put(key, PRESNET) == null
map
的put
方法返回旧值或者null
- 不允许存放重复 value 的集合,底层用
-
升级
jekyll
bundle update jekyll
orbundle update
Share
Sharing
One more thing
- Personal Medium Home Page: https://medium.com/@zhuxiang134
- Personal Website: https://zxsilence.cn/
标题:The 12th Week of ARTS:LinkedListCycle_141
作者:zhuSilence
地址:https://home.zxsilence.cn/articles/2018/11/11/1570340342473.html