目录

程序员子悠 · 好记性不如烂笔头

技术人生 X 人生技术

X

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

  1. Description
    Given a linked list, determine if it has a cycle in it.

  2. 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

  1. JS indexOf()

    1. indexOf('') == 0
  2. Java 序列化

    1. 实现 Serializable 接口,自动进行序列化;static 变量不会序列化;
    2. 实现 Externalizable 接口,需要手动序列化;static 变量会序列化;
  3. LinkedList 底层双向链表

    1. add时直接将最后一个节点赋值为last.next = newNode; newNode.prev = last
    2. get时,根据 indexsize >> 2,大小,决定从头遍历还是从尾部遍历;
  4. HashSet

    1. 不允许存放重复 value 的集合,底层用HashMap 实现;
    2. add 时基于map.put(key, PRESNET) == null
    3. mapput 方法返回旧值或者 null
  5. 升级jekyll

    1. bundle update jekyll or bundle update

Share

Sharing

常用算法笔记——持续更新

One more thing


标题:The 12th Week of ARTS:LinkedListCycle_141
作者:zhuSilence
地址:https://home.zxsilence.cn/articles/2018/11/11/1570340342473.html