![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode linked list
proudmore
这个作者很懒,什么都没留下…
展开
-
Leetcode 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 numbers and return it as a linke原创 2015-02-27 14:40:19 · 192 阅读 · 0 评论 -
Leetcode Intersection of two linked lists
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-03-06 06:16:24 · 114 阅读 · 0 评论 -
Leetcode Linked list sorting 问题
Insertion sort[code]public class Solution { public ListNode insertionSortList(ListNode head) { if(head==null || head.next==null)return head; ListNode d=new ListNode(0); d.ne原创 2015-03-05 14:45:46 · 170 阅读 · 0 评论 -
Leetcode 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 example, Given {1,2,3,4}, reorder it to {1,4原创 2015-03-05 12:28:28 · 135 阅读 · 0 评论 -
Leetcode 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 nodes in the end should remain as it is.You原创 2015-03-04 07:15:22 · 121 阅读 · 0 评论 -
Leetcode Linked list cycle问题
[code] 判断有没有cyclepublic class Solution { public boolean hasCycle(ListNode head) { if(head==null || head.next==null)return false; ListNode p=head.next.next, q=head.next; whi原创 2015-03-04 10:24:08 · 108 阅读 · 0 评论 -
Leetcode 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 of the list.[code]/** * Definition for singly-link原创 2015-03-04 10:07:34 · 153 阅读 · 0 评论 -
Leetcode LRU cache
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 if th原创 2015-03-04 09:03:42 · 174 阅读 · 0 评论 -
Leetcode Reverse linked list II
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 fol原创 2015-02-27 14:58:25 · 140 阅读 · 0 评论 -
Leetcode 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 only constant space. You原创 2015-02-28 14:59:57 · 177 阅读 · 0 评论 -
Leetcode Partition list
[code] Memory limit exceededpublic class Solution { public ListNode partition(ListNode head, int x) { if(head ==null || head.next==null)return head; ListNode d1=new ListNode(0), d2原创 2015-02-27 15:50:43 · 134 阅读 · 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.[code]public class Solution { public L原创 2015-02-28 14:42:16 · 137 阅读 · 0 评论 -
Leetcode Remove Nth node from end of list
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 end, the linke原创 2015-02-28 14:50:20 · 123 阅读 · 0 评论 -
Leetcode Merge sorted lists问题
merge two sorted lists[code]public class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { if(l1==null)return l2; if(l2==null)return l1; ListNode d=new Li原创 2015-03-11 07:58:50 · 129 阅读 · 0 评论