LeetCode_链表操作
文章平均质量分 70
sunp823
积跬步,至千里;积小流,成江海
展开
-
LeetCode_链表操作1—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. Y原创 2015-05-11 19:33:19 · 335 阅读 · 0 评论 -
LeetCode_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 of原创 2015-05-29 19:48:57 · 347 阅读 · 0 评论 -
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原创 2015-06-04 14:42:19 · 316 阅读 · 0 评论 -
判断链表是否有环及找到环的入口节点
判断链表中是否有环存在: 设置两个指针p,q,开始时两个指针均指向head; p每次向前移动一步,q每次移动两步;不断移动,若在移动过程中p和q重合(p == q)则说明有环(证明略)。 代码: struct ListNode { int val; struct ListNode *next; ListNode(int x):val(x), next(NULL原创 2015-08-22 23:33:07 · 716 阅读 · 0 评论