Prolem876-Submission Detail
Given a non-empty, singly linked list with head node head
, return a middle node of linked list.
If there are two middle nodes, return the second middle node.
Example 1:
1 | Input: [1,2,3,4,5] |
Example 2:
1 | Input: [1,2,3,4,5,6] |
Note:
- The number of nodes in the given list will be between
1
and100
.
key
题目输出单向链表的中间元素,有这么几个思路
- O(N)–>遍历放数组,1/2输出
return A[t / 2]
- O(N)–>根据中间特点,mid前进一格,end前进两格
Solution
第一次提交:0ms
1 | class Solution { |
第二次参考其他代码-提交:
1 | class Solution { |