Leetcode 206. Reverse Linked List (Easy) (cpp)
来源:互联网 发布:java swing 表格 编辑:程序博客网 时间:2024/04/29 05:08
Leetcode 206. Reverse Linked List (Easy) (cpp)
Tag: Linked List
Difficulty: Easy
/*206. Reverse Linked List (Easy)Reverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?*//** * 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 *p = head, *prev = NULL; while (head != NULL) { ListNode *post = head -> next; head -> next = prev; prev = head; head = post; } return prev; }};class Solution {public: ListNode* reverseList(ListNode* head) { if (head == NULL || head -> next == NULL) { return head; } ListNode *newhead = reverseList(head -> next); head -> next -> next = head; head -> next = NULL; return newhead; }};
0 0
- Leetcode 206. Reverse Linked List (Easy) (cpp)
- LeetCode 206. Reverse Linked List (Easy)
- Leetcode 206. Reverse Linked List cpp实现
- 206. Reverse Linked List(Linked List-Easy)
- 【Easy】206. Reverse Linked List
- 206. Reverse Linked List (Easy)
- Leetcode 141. Linked List Cycle (Easy) (cpp)
- Leetcode 234. Palindrome Linked List (Easy) (cpp)
- LeetCode-Easy部分标签为LinkedList 206. Reverse Linked List
- 【LeetCode】206.Reverse Linked List(Easy)解题报告
- [Leetcode 206, Easy] Reverse Linked List
- 【Leetcode-Easy-206】Reverse Linked List
- leetcode 206[easy]-Reverse Linked List
- leetcode 日经贴,Cpp code -Reverse Linked List
- 206. Reverse Linked List [easy] (Python)
- Easy-题目12:206. Reverse Linked List
- 【LeetCode】206.reverse linked list
- [leetcode] 206.Reverse Linked List
- 26javascript基于对象
- 可左右上下滑动切换图片的界面
- 简陋hash算法
- mysql sql语句的用法
- spring 事务详解
- Leetcode 206. Reverse Linked List (Easy) (cpp)
- angularjs自定义指令的用法
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] E 三分
- 安装oracle数据库软件报错
- 33.Python的单元测试工具——unittest(高级)
- Android Activity的四种launchmode
- 自定义动画--角度抖动、路径旋转、左右晃动
- des+base加密解密
- TCP option 3, Window Scale