
链表
peace in mind
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
[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转载 2015-03-31 11:19:29 · 354 阅读 · 0 评论 -
[Leetcode]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?判断一个连表是否有环,而且不使用额外空间=。=用一快一慢两个指针!class Solution {public: bool hasCycle(Lis原创 2015-03-31 11:06:50 · 480 阅读 · 0 评论 -
[leetcode] Palindrome Linked List
题目链接在此Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?要求用O(N)的时间和O(1)的空间,判断单链表是否为回文串。可以用一快一慢两个链表,溜一遍,寻找到链表的中原创 2015-08-12 10:47:55 · 395 阅读 · 0 评论 -
[Leetcode] Reverse Linked List
题目链接在此Reverse a singly linked list.反转一个单链表。别小看这道题啊,我TX面试上来就问这道题。当时我觉得用两个指针就够了——显然天真了,得用三个指针。这是一个循环的算法:struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL)原创 2015-08-05 17:19:21 · 493 阅读 · 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-04-01 00:11:06 · 390 阅读 · 0 评论 -
[Leetcode] Swap Nodes in Pairs & Reverse Nodes in k-Group
这是两道题。24. Swap Nodes in Pairs : 把链表两两相邻的结点互换值。25. Reverse Nodes in k-Group : 把链表中每k个结点组成的子链表翻转。其实24就是25在k=2时候的情况。就只讲25吧。Given a linked list, reverse the nodes of a linked list k at原创 2017-02-27 20:43:20 · 350 阅读 · 0 评论