init commit
This commit is contained in:
30
archive/algorithm/leetcode/876.c
Normal file
30
archive/algorithm/leetcode/876.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <math.h>
|
||||
|
||||
// 链表的中间结点
|
||||
// https://leetcode-cn.com/problems/middle-of-the-linked-list/
|
||||
|
||||
struct ListNode
|
||||
{
|
||||
int val;
|
||||
struct ListNode *next;
|
||||
};
|
||||
|
||||
struct ListNode *middleNode(struct ListNode *head)
|
||||
{
|
||||
int len = 0;
|
||||
struct ListNode *p1 = head, *p2 = head->next;
|
||||
while (p2 != NULL)
|
||||
{
|
||||
p1 = p1->next;
|
||||
p2 = p2->next;
|
||||
len++;
|
||||
if (p2 == NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
p2 = p2->next;
|
||||
}
|
||||
return p1;
|
||||
}
|
Reference in New Issue
Block a user