Java for LeetCode 206 Reverse Linked List
2024-08-24 01:39:28
Reverse a singly linked list.
解题思路:
用Stack实现,JAVA实现如下:
public ListNode reverseList(ListNode head) {
if(head==null)
return null;
Stack<ListNode> stack =new Stack<ListNode>();
ListNode temp=head;
while(temp!=null){
stack.push(temp);
temp=temp.next;
}
head=stack.pop();
temp=head;
while(!stack.isEmpty()){
temp.next=stack.pop();
temp=temp.next;
}
temp.next=null;
return head;
}
最新文章
- putpixel
- int *p()与int (*p)()的区别
- ajax普通弹窗;Bootstrp弹窗
- 洛谷P1519 穿越栅栏 Overfencing
- php5 date()获得的时间不是当前时间
- UNIX标准化及实现之限制
- 怎样在Ubuntu Scope中定义设置变量并读取
- TLD算法原理--学习理解之(二)
- SpringCloud-day08-Hystrix断路器
- Python学习day1 初识python&;环境安装
- N球M盒
- Pandas 基础(8) - 用 concat 组合 dataframe
- Spark:java.net.BindException: Address already in use: Service &#39;SparkUI&#39; failed after 16 retries!
- _itemmod_nopatch、_itemmod_nopatch_level、_itemmod_nopatch_spell、_itemmod_nopatch_src、_itemmod_nopatch_stat、_itemmod_nopatch_stat_prefix
- (转+整理)C#中动态执行代码
- C++ 11保留小数点的四舍五入方案
- codeforces水题100道 第二十五题 Codeforces Round #197 A. Helpful Maths (Div. 2) (strings)
- 二、django rest_framework源码之认证流程剖析
- python2-url编解码
- html表格设置