LeetCode-Reverse Linked List-解题报告

原创 2015年07月08日 18:36:37

原题链接 https://leetcode.com/problems/reverse-linked-list/

Reverse a singly linked list.


反转链表


水过。


/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
		if (head == NULL)return NULL;
		ListNode* tmp = head;
		ListNode* current = tmp;

		tmp = tmp->next;
		current->next = NULL;

		while (tmp != NULL)
		{
			ListNode* t = tmp->next;
			tmp->next = current;
			current = tmp;
			tmp = t;
		}
		return current;
	}
};


版权声明:

相关文章推荐

LeetCode 206. Reverse Linked List 解题报告

LeetCode 206. Reverse Linked List 解题报告

【LeetCode】206. Reverse Linked List 解题报告

转载请注明出处:http://blog.csdn.net/crazy1235/article/details/51820937Subject 出处:https://leetcode.com/pro...

LeetCode 92. Reverse Linked List II 解题报告

LeetCode 92. Reverse Linked List II 解题报告题目描述Reverse a linked list from position m to n. Do it in-pla...

【LeetCode】Reverse Linked List 解题报告

Reverse Linked List[LeetCode]https://leetcode.com/problems/reverse-linked-list/Total Accepted: 10547...

LeetCode(114) Flatten Binary Tree to Linked List解题报告

Given a binary tree, flatten it to a linked list in-place.For example, Given 1 / \ ...

[leetcode] 142. Linked List Cycle II 解题报告

题目链接:https://leetcode.com/problems/linked-list-cycle-ii/ Given a linked list, return the node wher...

【LeetCode】Linked List Cycle 解题报告

Linked List Cycle[LeetCode]https://leetcode.com/problems/linked-list-cycle/Total Accepted: 102417 To...

[Leetcode] 142. Linked List Cycle II 解题报告

题目: Given a linked list, return the node where the cycle begins. If there is no cycle, return n...

[leetcode] 382. Linked List Random Node 解题报告

题目链接: https://leetcode.com/problems/linked-list-random-node/ Given a singly linked list, return a ...

[leetcode]114. Flatten Binary Tree to Linked List@Java解题报告

https://leetcode.com/problems/flatten-binary-tree-to-linked-list/description/ Given a bin...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)