原创 Linked List Cycle II

Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify t

原创 Insertion Sort List

題意:實現鏈表的插入排序  插入排序是一種O(n^2)複雜度的算法,就是每次循環找到一個元素在當前排好的結果中相對應的位置,然後插進去,經過n次迭代之後就得到排好序的結果了。 /** * Definition for singly-li

原创 Partition List

Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equa

原创 Reorder List

Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place witho

原创 Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should ret

原创 Reverse Linked List I,II

Reverse a singly linked list. 題意:反轉鏈表 方法一:遍歷 思路:使用輔助節點dummy。初始化時dummy..next指向head,並從第二個節點開始遍歷, 把遍歷過的節點一次插入在dummy節點之後,最後

原创 Palindrome Linked List 迴文鏈表

Given a singly linked list, determine if it is a palindrome. 題意: 判斷一個鏈表是否是迴文鏈表,迴文鏈表就是無論從左讀還是從右讀都一樣 例如    1->2->3->2->1

原创 Rotate List

Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NU

原创 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? 題意:判斷鏈

原创 Missing Number

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.

原创 Delete Node in a Linked List

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed

原创 Merge Two Sorted Lists

Merge two sorted linked lists and return it as a new list.  The new list should be made by splicing together the nodes

原创 Majority Element II

Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in

原创 Intersection of Two Linked Lists

Write a program to find the node at which the intersection of two singly linked lists begins. For example, the follow

原创 Palindrome Number

題目:判斷一個數是否是迴文數字   迴文數字就是正着讀和反着讀一樣,比如12321. 要求:不能使用額外的內存空間 思路:反轉數字,然後和反轉前的數字對比,相等即返回true public class Solution { pub