博客
关于我
[LeetCode] 876.求链表的中间节点 , [剑指offer]求链表中倒数第K个节点
阅读量:62 次
发布时间:2019-02-26

本文共 939 字,大约阅读时间需要 3 分钟。

1. ????????

????

????????????????????????????????????????????????????????????????????????????????????????????????????????

????

struct ListNode* middleNode(struct ListNode* head) {    struct ListNode* fast = head;    struct ListNode* slow = head;    while (fast->next != NULL) {        slow = slow->next;        fast = fast->next->next;    }    return slow;}

2. ???????K???

????

???????????K??????????????????????????????K???????????????????????????????????K????

????

struct ListNode* FindKthToTail(struct ListNode* pListHead, int k) {    if (pListHead == NULL || k <= 0) {        return NULL;    }    struct ListNode* fast = pListHead;    struct ListNode* slow = pListHead;    for (int i = 0; i < k; i++) {        if (fast == NULL) {            return NULL;        }        fast = fast->next;    }    while (fast != NULL) {        slow = slow->next;        fast = fast->next;    }    return slow;}

?????????????????????????????????????????

转载地址:http://bjbz.baihongyu.com/

你可能感兴趣的文章
pytest:4种方法实现 - 重复执行用例 - 展示迭代次数
查看>>
Pytest:一个卓有成效的测试工具
查看>>
python
查看>>
Python "HTTP Error 403: Forbidden"
查看>>
python %ns的作用
查看>>
Python + Appium 之 APP 自动化测试,坑点汇总!(建议收藏)
查看>>
Python + Appium 自动化操作微信入门(超详细)
查看>>
Python + Pytest 自动化框架的用例依赖实操
查看>>