LeetCode-206. Reverse Linked List
来源:互联网 发布:域名检测接口 编辑:程序博客网 时间:2024/06/04 18:29
206. 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||head->next==NULL) return head; ListNode *tnow=head, *tnext=head->next, *tone; head->next=NULL; while(tnext != NULL){ tone = tnext->next; tnext->next = tnow; tnow = tnext; tnext = tone; } return tnow; }};
用递归的方式:
class Solution {public: ListNode* reverseList(ListNode* head) { if (!head || !(head -> next)) return head; ListNode* node = reverseList(head -> next); head -> next -> next = head; head -> next = NULL; return node; }};
0 0
- 【LeetCode】206.reverse linked list
- [leetcode] 206.Reverse Linked List
- [leetcode] 206. Reverse Linked List
- 206. Reverse Linked List LeetCode
- leetCode 206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- [LeetCode]206. Reverse Linked List
- 【LeetCode】206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- leetcode 206. Reverse Linked List
- 【LeetCode】206. Reverse Linked List
- leetcode 206. Reverse Linked List
- LeetCode *** 206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- 【leetcode】206. Reverse Linked List
- [LeetCode]206. Reverse Linked List
- #leetcode#206. Reverse Linked List
- Web应用安全之CSRF
- Boost Serialization 库
- Java学习之HttpURLConnection添加对https信任
- 关于编程中的内存管理
- Revit开发之调用Revit命令的另一种方法
- LeetCode-206. Reverse Linked List
- 开发技术选型参考
- 十、今年暑假不AC
- 功能点五种方法比较
- 通过 SQL Anywhere Profiler 来对应用程序进行故障排除及调优
- 计算机视觉领域的教授、专家及研究所官方主页
- Linux中对MySQL优化
- Spring在Web项目中的应用-添加ServletContext监听器
- meta name="viewport" content="width=device-width,initial-scale=1.0" 解释