- 博客(17)
- 收藏
- 关注
原创 Leetcode: Add Two Numbers
Add Two Numbers 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
2015-06-20 11:05:49
426
原创 Leetcode:Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search Tree Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 解析:将链表转化为二分查找树,使用递归依次找到中点生成树节点即可
2015-06-20 11:02:38
424
原创 Leetcode:Copy List with Random Pointer
Copy List with Random Pointer A 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
374
原创 Leetcode:Insertion Sort List
Insertion Sort List Sort a linked list using insertion sort. 解析:使用插入排序对链表节点进行排序 代码: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode
2015-06-20 10:27:10
386
原创 Leetcode:Linked List Cycle II
Linked List Cycle II Given 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
348
原创 Leetcode: Linked List Cycle
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? 解析:判断一个链表是否有环,使用快慢指针,若有环两指针会在某点重合 代码: /** * Definiti
2015-06-20 10:17:38
319
原创 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
281
原创 Leetcode:Partition List
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 equal to x. You should preserve the original relative
2015-06-20 10:03:43
355
原创 Leetcode: Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List II Given 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
361
原创 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
311
原创 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
369
原创 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
343
原创 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
426
原创 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
280
原创 Leetcode: Swap Nodes in Pairs
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 return the list as 2->1->4->3. Your algorithm should use
2015-06-13 14:05:58
293
原创 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
415
原创 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
414
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅