2023每日刷题(三十三)
Leetcode—876.链表的中间结点
实现代码
/*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/
struct ListNode* middleNode(struct ListNode* head) {struct ListNode* fast = head, *slow = head;if(fast->next == NULL) {return slow;}if(fast->next->next == NULL) {return slow->next;}while(fast != NULL) {fast = fast->next;if(fast != NULL) {fast = fast->next;} else {return slow;}slow = slow->next;}return slow;
}
运行结果
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!