lintcode--翻转链表
来源:互联网 发布:mac安装win10时蓝屏 编辑:程序博客网 时间:2024/05/17 22:32
翻转一个链表
样例
给出一个链表1->2->3->null,这个翻转后的链表为3->2->1->null
/**
* Definition for ListNode.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int val) {
* this.val = val;
* this.next = null;
* }
* }
*/
public class Solution {
public ListNode reverse(ListNode head) {
// write your code here
ListNode pre = null;
ListNode temp = null;
while(head!=null){
temp = head.next;//保存下一节点
head.next = pre;
//向后移动
pre = head;
head = temp;//下一个
}
//返回前指针;
return pre;
}
}
阅读全文
0 0
- LintCode-翻转链表
- lintcode 翻转链表
- LintCode:翻转链表
- lintcode,翻转链表
- 翻转链表,lintcode
- Lintcode 翻转链表
- LintCode 翻转链表
- 翻转链表-LintCode
- LintCode : 翻转链表
- [Lintcode]翻转链表
- lintcode--翻转链表
- Lintcode翻转链表
- LintCode 翻转链表
- lintcode翻转链表
- LintCode 翻转链表
- Lintcode:翻转链表
- LintCode:翻转链表 II
- 【LintCode】翻转链表 II
- 安装XAMPP登陆localhost出现的问题
- MySQL数据去重--distinct的使用
- Zedboard学习(六):XADC读取数据
- 个人计划整理
- Kotlin 设计模式-工厂
- lintcode--翻转链表
- 机器学习笔记--GMM模型
- 逃离迷宫
- Android实现模拟表单上传
- APP开发步骤
- gradle providedCompile、compile与runtime的使用
- 虚幻4中模型勾边
- bzoj 1690: [Usaco2007 Dec]奶牛的旅行 spfa+二分答案
- 玲珑杯1146-图论你先敲完模板【dp方程】