剑指offer-15.反转链表
来源:互联网 发布:淘宝服装图片拍摄技巧 编辑:程序博客网 时间:2024/06/03 13:47
题目:输入一个链表,反转链表后,输出链表的所有元素。
思路:反转通常使用栈进行反转,栈一个特点是后进先出。
/*struct ListNode {int val;struct ListNode *next;ListNode(int x) :val(x), next(NULL) {}};*/class Solution {public: ListNode* ReverseList(ListNode* pHead) { stack<int>temp; ListNode* result = pHead; while (result != NULL) { temp.push(result->val); result = result->next; } result = pHead; while (result != NULL) { if (!temp.empty()) { result->val = temp.top(); temp.pop(); result = result->next; } } return pHead; }};
0 0
- 剑指offer-15.反转链表
- 剑指Offer--15.反转链表
- [剑指Offer] 15.反转链表
- 剑指offer:反转链表
- 剑指offer--反转链表
- 剑指offer--反转链表
- 剑指Offer-反转链表
- 《剑指offer》反转链表
- 剑指 offer:反转链表
- 剑指offer-反转链表
- 剑指offer 反转链表
- 剑指offer-反转链表
- 剑指offer:反转链表
- [剑指offer]反转链表
- 《剑指offer》-反转链表
- 剑指Offer:反转链表
- 剑指offer----反转链表
- 剑指offer|反转链表
- 开发过程中遇到图片加载之后只有一部分的情况
- 01 什么是webgl
- zebra线程管理源码简析
- POJ 2481 Cows(树状数组)
- 9个PHP魔术方法总结
- 剑指offer-15.反转链表
- Android--Parcelable接口的用法
- 欢迎使用CSDN-markdown编辑器
- HTTP Status 400 – Bad Request
- iOS预编译文件添加
- 20个代码生成框架
- CF#798 A. Mike and palindrome(水题)
- 【linux】ubuntu右键添加终端
- 《CSS权威指南》读书笔记8