翻转链表-LintCode
来源:互联网 发布:淘宝关键词热度 编辑:程序博客网 时间:2024/05/21 14:52
描述:
翻转一个链表。
样例:
给出一个链表1->2->3->null,这个翻转后的链表为3->2->1->null
思路:
新建一个链表,把给出链表的节点利用头插法插入新链表,就得到了翻转的链表。
/** * Definition of ListNode * * class ListNode { * public: * int val; * ListNode *next; * * ListNode(int val) { * this->val = val; * this->next = NULL; * } * } */class Solution {public: /** * @param head: The first node of linked list. * @return: The new head of reversed linked list. */ ListNode *reverse(ListNode *head) { // write your code here ListNode *r=new ListNode(0); while(head!=NULL) { ListNode *temp=new ListNode(0); temp->val=head->val; temp->next=r->next; r->next=temp; head=head->next; } return r->next; }};
0 0
- LintCode-翻转链表
- lintcode 翻转链表
- LintCode:翻转链表
- lintcode,翻转链表
- 翻转链表,lintcode
- Lintcode 翻转链表
- LintCode 翻转链表
- 翻转链表-LintCode
- LintCode : 翻转链表
- [Lintcode]翻转链表
- lintcode--翻转链表
- Lintcode翻转链表
- LintCode 翻转链表
- lintcode翻转链表
- LintCode 翻转链表
- Lintcode:翻转链表
- LintCode:翻转链表 II
- 【LintCode】翻转链表 II
- mysql的关于TABLE_SCHEMA的sql语句和nformation_schema表
- Linux内核配置以及Make menuconfig过程分析
- 【逆序对】【线段树】【树状数组】Data Structure Special Training 1 T1 rotinv 题解
- 子元素垂直、左右居中的问题
- PAT L2-008. 最长对称子串(25) (暴力,Manacher算法和DP解决)
- 翻转链表-LintCode
- jdk 的下载,安装,以及重装
- CDOJ(UESTC)24 8球胜负(eight)~水题
- Shell 中字符串处理1
- 朱有鹏:对嵌入式工程师的一些小建议
- mybatis 开启日志记录 打印sql语句
- 从这里开始
- PAT L2-007. 家庭房产 并查集的结构体合并
- 2017某公司Android实习生笔试题总结