
LeetCode LinkedList
文章平均质量分 76
Spencer_Lin
If you fight for your dream, one day....
展开
-
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 order of the nodes in each o原创 2014-07-17 05:22:21 · 319 阅读 · 0 评论 -
Reorder List Java
/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } *//* * key t原创 2014-07-20 16:34:09 · 355 阅读 · 0 评论 -
Add Two Numbers LeetCode 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 as a link原创 2014-07-17 09:04:30 · 394 阅读 · 0 评论 -
Rotate List Java
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.Idea: dummy node 1.find leng原创 2014-08-22 08:40:51 · 395 阅读 · 0 评论 -
Insertion Sort List Java
Problem: Sort a linked list using insertion sort.public class Solution { public ListNode insertionSortList(ListNode head) { if(head==null || head.next==null) return head;原创 2014-08-22 08:53:17 · 384 阅读 · 0 评论 -
Remove Nth Node From End of List Java
The key of this problem is to locate the node prior the removing node:There are two ways to locate原创 2014-07-17 08:23:47 · 318 阅读 · 0 评论 -
Swap Nodes in Pairs 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原创 2014-07-14 14:47:50 · 519 阅读 · 0 评论 -
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.*//** * Definition for singly-linked list. * publ原创 2014-07-14 13:46:59 · 336 阅读 · 0 评论 -
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,Given 1->2->3->原创 2014-07-14 12:18:30 · 372 阅读 · 0 评论 -
Reverse Linked List
The question was asked in Google phone interview原创 2014-07-16 14:14:19 · 556 阅读 · 0 评论 -
Remove Duplicates from Sorted List
/*Remove Duplicates from Sorted List: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原创 2014-07-14 12:20:46 · 304 阅读 · 0 评论 -
Linked List Cycle Java
/*Linked List Cycle Total Accepted: 22080 Total Submissions: 62658 My SubmissionsGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?*/原创 2014-07-11 09:41:21 · 454 阅读 · 0 评论 -
Linked List Cycle II Java
/*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?*//** * Definition for singly-linked list.原创 2014-07-11 11:47:43 · 355 阅读 · 0 评论 -
Merge k Sorted Lists Java
/* * Key to solve: Since it require to sort input lists, and merge together, * then output one. We can use the DataStructure of PriorityQueue that * sorting elements during insert operation. The原创 2014-07-19 16:57:52 · 370 阅读 · 0 评论 -
Reverse Nodes in k-Group Java
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ /*Key原创 2014-07-20 11:08:17 · 352 阅读 · 0 评论 -
LRU Cache Java
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key i原创 2014-07-21 06:38:41 · 374 阅读 · 0 评论 -
Reverse Linked List II 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 satisfy the foll原创 2014-07-16 13:50:37 · 669 阅读 · 0 评论