55、链表入环节点

思路:

快慢指针,快指针一次两步,慢指针一次一步

相遇时,慢指针不变,快指针指向头部

再次遍历,各一步,相遇时则是入环节点

public class Solution {

    public ListNode EntryNodeOfLoop(ListNode pHead)
    {
        ListNode fast=pHead;
        ListNode slow=pHead;
        while(fast!=null && fast.next!=null)//快指针两步,故都要判断
        {
            fast=fast.next.next;
            slow=slow.next;
            if(fast==slow)
                break;
        }
        if(fast==null || fast.next==null)
           return null;
        fast=pHead;
        while(fast!=slow)
        {
            fast=fast.next;
            slow=slow.next;
            
        }
        return slow;
    }
}

 

根据下面的函数,函数调用以及宏和变量分析主要实现什么功能 #include “psram_conf.h” #define PSRAM_END_ADDR (M55C0_PSRAM_BASE + M55C0_PSRAM_SIZE) #define PSRAM_END_RESERVE_START (PSRAM_END_ADDR - PSRAM_END_RESERVE_LEN) static struct boot_detection *p_bd = (struct boot_detection *)PSRAM_END_RESERVE_START; static void oplus_boot_detection_update_crc(void) { uint32_t crc_len = sizeof(struct boot_detection) - sizeof(p_bd->fixed_tail) - sizeof(p_bd->crc); #ifdef IS_BOOTLOADER p_bd->debug_boot_modify++; #endif #ifdef IS_APP p_bd->debug_app_modify++; #endif #ifdef IS_RECOVERY p_bd->debug_recovery_modify++; #endif p_bd->crc = crc32_c(0, (uint8_t*)p_bd, crc_len); BD_LOGI("BD times:%d, flag:%d. Modify:%d, %d, %d", p_bd->boot_times, p_bd->err_flag, p_bd->debug_boot_modify, p_bd->debug_recovery_modify, p_bd->debug_app_modify); } static void oplus_boot_detection_init_struct(void) { memset(p_bd, 0, sizeof(struct boot_detection)); p_bd->fixed_head = BOOT_DETECTION_FIXED_HEAD; p_bd->fixed_tail = BOOT_DETECTION_FIXED_TAIL; oplus_boot_detection_update_crc(); } static int32_t oplus_boot_detection_is_valid(void) { uint32_t crc; uint32_t crc_len = sizeof(struct boot_detection) - sizeof(p_bd->fixed_tail) - sizeof(p_bd->crc); crc = crc32_c(0, (uint8_t*)p_bd, crc_len); if ((p_bd->fixed_head != BOOT_DETECTION_FIXED_HEAD) || (p_bd->fixed_tail != BOOT_DETECTION_FIXED_TAIL) || (crc != p_bd->crc)) { BD_LOGE("BD invalid. Fixed:%Xh,%Xh, CRC:%Xh,%Xh", p_bd->fixed_head, p_bd->fixed_tail, crc, p_bd->crc); return 0; } return 1; } void oplus_boot_detection_clear_times(void) { if (!oplus_boot_detection_is_valid()) { oplus_boot_detection_init_struct(); } p_bd->boot_times = 0; p_bd->err_flag = 0; oplus_boot_detection_update_crc(); BD_LOGI("BD clear times"); }
最新发布
08-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值