[闲聊] LeetCode 876

楼主: sustainer123 (caster)   2023-01-06 13:24:16
876. Middle of the Linked List
给你一个linked list,请找出它的middle node,
如长度为偶数,中间有二middle node,则取第二个。
Example 1:
Input: head = [1,2,3,4,5]
Output: [3,4,5]
Explanation: The middle node of the list is node 3.
Input: head = [1,2,3,4,5,6]
Output: [4,5,6]
Explanation: Since the list has two middle nodes with values 3 and 4, we
return the second one.
思路:
linked list无法直接得知长度,所以先设另一linked list为i,使i=head,
将i跑完一遍,便能得知长度。
之后将长度/2,为了使小数点进位,所以加上round()函式。
最后用循环跑出middle node,回传head。
C Code
作者: SecondRun (雨夜琴声)   2023-01-06 13:26:00
大师
作者: Jaka (Jaka)   2023-01-06 13:29:00
大师
楼主: sustainer123 (caster)   2023-01-06 13:34:00
你们才是大师 我等等要刷第一题medium 觉得恐慌

Links booklink

Contact Us: admin [ a t ] ucptt.com