Leetcode
文章平均质量分 66
spirit_young
这个作者很懒,什么都没留下…
展开
-
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 · 272 阅读 · 0 评论 -
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 · 342 阅读 · 0 评论 -
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 · 342 阅读 · 0 评论 -
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 · 307 阅读 · 0 评论 -
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 · 283 阅读 · 0 评论 -
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 · 298 阅读 · 0 评论 -
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 · 297 阅读 · 0 评论 -
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 · 268 阅读 · 0 评论 -
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 · 232 阅读 · 0 评论 -
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 · 252 阅读 · 0 评论 -
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 · 338 阅读 · 0 评论 -
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 · 340 阅读 · 0 评论 -
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 · 239 阅读 · 0 评论 -
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 · 309 阅读 · 0 评论 -
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 · 262 阅读 · 0 评论 -
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 · 235 阅读 · 0 评论 -
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 · 357 阅读 · 0 评论