
Liked List
文章平均质量分 52
pengweixuan008
这个作者很懒,什么都没留下…
展开
-
203.Remove Linked List Elements(删除链表中值为X的结点)
题目:Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5思路:新建一个val=-1的头节点,从he原创 2015-07-28 16:22:20 · 297 阅读 · 0 评论 -
206.Reverse Linked List(单链表逆置)
Reverse a singly linked list./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } **/ 方法原创 2015-07-28 16:12:40 · 363 阅读 · 0 评论 -
二叉搜索树与双向链表转化
1:由于要求链表是有序的,可以借助二叉树中序遍历,因为中序遍历算法的特点就是从小到大访问结点。当遍历访问到根结点时,假设根结点的左侧已经处理好,只需将根结点与上次访问的最近结点(左子树中最大值结点)的指针连接好即可。进而更新当前链表的最后一个结点指针。2:由于中序遍历过程正好是转换成链表的过程,即可采用递归处理struct BinaryTreeNode {转载 2015-08-09 16:46:30 · 372 阅读 · 0 评论 -
141.Linked List Cycle (判断一个单链表是否有环)
public class Solution { public boolean hasCycle(ListNode head) { ListNode slow = head, fast = head; while (fast != null && fast.next != null) { slow = slow.next;原创 2015-07-30 15:06:19 · 220 阅读 · 0 评论 -
160.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-07-30 14:22:22 · 255 阅读 · 0 评论 -
83.Remove Duplicates from Sorted List (删除单链表中重复结点)
For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.public class Solution { public ListNode deleteDuplicates(ListNode head) { if(head==null) return n原创 2015-08-03 15:28:11 · 313 阅读 · 0 评论 -
19.Remove Nth Node From End of List(移除单链表中倒数第N个结点)
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,原创 2015-08-03 14:37:39 · 326 阅读 · 0 评论