是差点运气,可我一直在努力!
当前进程:
开始时间:2020.10.20结束时间:undefined
注意: 从今天开始,将使用Java语言,继续进行刷题计划,原计划的JavaScript / TypeScript语言刷题之路暂时一段落。
原仓库:https://github.com/Cundefined/JavaScript-or-TypeScript-for-LeetCode
GitHub仓库:https://github.com/Cundefined/Java-for-LeetCode
1、题目要求
( LeetCode – 第143题 ) 重排链表
2、解题思路
线性表
+双指针
3、Java Solution
class Solution {
public void reorderList(ListNode head
) {
if(head
== null
|| head
.next
== null
) {
return;
}
List
<ListNode> list
= new ArrayList<ListNode>();
ListNode cur
= head
;
while(cur
!= null
) {
list
.add(cur
);
cur
= cur
.next
;
}
int l
= 0;
int r
= list
.size() - 1;
while(l
< r
) {
list
.get(l
).next
= list
.get(r
);
l
++;
if(l
== r
) {
break;
}
list
.get(r
).next
= list
.get(l
);
r
--;
}
list
.get(l
).next
= null
;
}
}