LeetCode_Reverse Linked List
来源:互联网 发布:防蹭网软件手机版 编辑:程序博客网 时间:2024/05/04 04:16
一.题目
Reverse Linked List
Total Accepted: 9559 Total Submissions: 28250My SubmissionsReverse a singly linked list.
click to show more hints.
Hint:
A linked list can be reversed either iteratively or recursively. Could you implement both?
Show Tags
Have you met this question in a real interview?
Yes
No
Discuss
二.解题技巧
这是一道简单的链表反转的题,并不考察什么算法,只是考察链表的基础知识。
三.实现代码
/*** Definition for singly-linked list.* struct ListNode {* int val;* ListNode *next;* ListNode(int x) : val(x), next(NULL) {}* };*/#include <iostream>struct ListNode{ int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution{public: ListNode* reverseList(ListNode* head) { ListNode* Pre = NULL; ListNode* Now = head; ListNode* Next = NULL; while(Now) { Next = Now->next; Now->next = Pre; Pre = Now; Now = Next; } return Pre; }};
四.体会
这是一道简单的题,基础题。
版权所有,欢迎转载,转载请注明出处,谢谢
0 1
- LeetCode_Reverse Linked List II
- Leetcode_reverse-linked-list-ii
- leetcode_Reverse Linked List
- LeetCode_Reverse Linked List
- LeetCode_Reverse Linked List II
- LeetCode_reverse-linked-list
- Linked List
- linked list
- linked list
- Linked List
- Linked List
- Linked List
- linked list
- Linked List
- Linked List
- Linked list
- Linked List
- linked list 倒转linked list
- 一些开源软件的列表
- SQL中IN和EXISTS用法的区别,sql中exists,not exists的用法
- [智力题]1395: Planting Tree
- android学习杂记(1)--Intent传递对象数据
- call and apply
- LeetCode_Reverse Linked List
- html基础学习之不同浏览器的视频播放效果
- android中menu创建及相应
- $(document).ready()和window.onload的区别
- Java获取文件夹中所有文件
- 实现文件按时间排序功能
- MFC EDIT控件多行滚动
- SpringMVC+MyBatis+C3P0连接池详细配置
- 创建并启动一个xen半虚拟化PV客户机