自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Leetcode: Add Two Numbers

Add Two NumbersYou 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

2015-06-20 11:05:49 352

原创 Leetcode:Convert Sorted List to Binary Search Tree

Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.解析:将链表转化为二分查找树,使用递归依次找到中点生成树节点即可

2015-06-20 11:02:38 357

原创 Leetcode:Copy List with Random Pointer

Copy List with Random PointerA linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy o

2015-06-20 10:34:39 320

原创 Leetcode:Insertion Sort List

Insertion Sort ListSort a linked list using insertion sort.解析:使用插入排序对链表节点进行排序代码:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode

2015-06-20 10:27:10 315

原创 Leetcode:Linked List Cycle II

Linked List Cycle IIGiven a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?解析:其

2015-06-20 10:20:47 279

原创 Leetcode: Linked List Cycle

Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?解析:判断一个链表是否有环,使用快慢指针,若有环两指针会在某点重合代码:/** * Definiti

2015-06-20 10:17:38 270

原创 Leetcode: Merge k Sorted Lists

Merge k Sorted Lists Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.解析:1. 题目大意是给出k个链表,需要你将他们合并为一个链表。   2. 主要思路为将给

2015-06-20 10:08:12 245

原创 Leetcode:Partition List

Partition ListGiven 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

2015-06-20 10:03:43 294

原创 Leetcode: Remove Duplicates from Sorted List II

Remove Duplicates from Sorted List IIGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,

2015-06-19 23:57:04 308

原创 Leetcode: Reorder List

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 without altering the nodes' values.For exampl

2015-06-18 22:22:19 262

原创 Leetcode: Reverse Linked List I

描述: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->

2015-06-13 16:02:21 319

原创 Leetcode: Reverse Nodes in k-Group

Reverse Nodes in k-Group描述:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out

2015-06-13 15:43:05 282

原创 Leetcode: 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->NULL and k = 2,return 4->5->1->2->3->NULL

2015-06-13 14:23:25 355

原创 Leetcode: Sort List

Sort List描述:Sort a linked list in O(n log n) time using constant space complexity.解析:由于要求时间复杂度为O(n log n),空间复杂度为O(n),使用分治类的排序算法才能符合要求。这里采取的是归并排序,运用递归将原始链表进行分割,然后再把子链表依次按顺序合并,实现排序目的。代码:/*

2015-06-13 14:10:31 244

原创 Leetcode: Swap Nodes in Pairs

Swap Nodes in PairsGiven 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

2015-06-13 14:05:58 252

原创 Leetcode Note: Linked List Easy Section Part 2

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 of the first two lists.解析:将两个排列好的链表合并代码

2015-06-07 19:12:05 370

原创 Leetcode Note: Linked List Easy Section Part 1

Reverse Linked List描述:Reverse a singly linked list.解析:反转一个链表,基础中的基础,不解释代码:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; *

2015-06-07 16:14:51 355

空空如也

空空如也

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

TA关注的人

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