自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(13)
  • 收藏
  • 关注

原创 LeetCode143之ReorderList的Java题解

题目: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 without altering the nodes' values.For example,Given {1,2,3,4}, reord

2015-05-07 20:57:31 500

原创 LeetCode24之SwapNodesInPairs的Java 题解

题目:Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant

2015-05-07 16:28:59 668

原创 LeetCode86之PartionList的java题解

题目:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in

2015-05-07 12:10:52 530

原创 LeetCode2之AddTwoNumbers的java题解

题目:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it

2015-05-07 11:14:08 476

转载 LeetCode 148之Sort List的java题解

转自:http://blog.csdn.net/worldwindjp/article/details/18986737题目:Sort a linked list in O(n log n) time using constant space complexity.解答:解题报告:就是对一个链表进行归并排序。主要考察3个知识点,知识点1:归并排序的整体思想知识点

2015-05-07 10:00:07 2084

原创 LeetCode 160之Intersection of Two Linked Lists 的Java题解

题目:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘

2015-05-06 21:31:51 794

原创 LeetCode 82之Remove Duplicates from Sorted List II的Java题解

题目:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Gi

2015-05-06 17:23:34 1082

原创 LeetCode 19之Remove Nth Node From End of List的Java题解(三种解法)

题目:Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the

2015-05-06 11:35:54 558

原创 LeetCode83之Remove Duplicates from Sorted List的Java题解

题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.解答:因为是有序链表,所以去

2015-05-06 09:40:49 1068

原创 LeetCode92之Reverse Linked ListII的 Java题解

题目:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n sa

2015-05-05 18:06:05 606 1

原创 LeetCode206之Reverse Linked List Java题解

题目:Reverse a singly linked list.解题:采用最直接的思路,从链表的第二个节点开始向后遍历,将每一个遍历的节点插入作为当前的第一个节点,为了方便操作,我们定义一个fakeNode节点指向第一个节点,后面需要插入的节点需要做两件事:一,使需要插入的节点的next指向当前链表中的第一个节点(即fakeNode的下一个节点);二,让fakeNode的next指

2015-05-05 16:15:03 1811

原创 LeetCode142之Linked List CycleII java题解

在上一篇文章中,我们通过判断一快一慢两个指针是否会相遇来判断这个链表是否有环,但是请注意,相遇的节点不一定是环的第一个起点,要找出环的起点我们可以用下面这种思路:用哈希表记录从表头开始遍历的节点,如果遇到已经存在的节点那么这个节点就是环的起点。下面是实现的代码: public static ListNode detectCycle(ListNode head) { if(head==

2015-05-05 11:01:54 460

原创 LeetCode141之Linked List Cycle java题解

之前我的一个同学在面试腾讯的时候问到一个问题:如何判断一个链表存在环?当时我同学说了两种思路:一,记录某一个节点,遍历链表看最终是否能回到这个节点;二,设置一个快一个慢的指针(即一个一次走一步,一个一次走两步)如果他们能够相遇就说明有环。看到Leetcode这题判断是否有环的时候,发现如果链表本身如果不是一个标准环的话是无法用第一种思路判断出来的。相对来说,一快一慢这种解法更有通用性。下面就是

2015-05-05 10:04:25 1395

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除