HOT100-2-二叉树最近公共祖先
题目描述给定一个二叉树, 找到该树中两个指定节点的最近公共祖先。 百度百科中最近公共祖先的定义为:“对于有根树 T 的两个节点 p、q,最近公共祖先表示为一个节点 x,满足 x 是 p、q 的祖先且 x 的深度尽可能大(一个节点也可以是它自己的祖先)。” 示例 1: 123输入:root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1输出:3解释:节点 5 和节点 1 的最近公共祖先是节点 3 。 具体见题目链接。 算法思路 ...
HOT100-1-相交链表
题目描述给你两个单链表的头节点 headA 和 headB ,请你找出并返回两个单链表相交的起始节点。如果两个链表不存在相交节点,返回 null 。 图示两个链表在节点 c1 开始相交 : 如图所示,则输出C1;具体见题目链接:题目链接 题目思路这道题目我是不会的……我只能想到暴力破解,就是通过两层循环进行遍历,找到最开始的地址相同的节点,伪代码差不多是这样:: 1234567891011tmpA = headA;while(tmpA != NULL) { tmpB = headB; while (tmpB != NULL) { if (tmpA != tmpB) { return tmpA; } tmpB = tmpB->next; }} return NULL; ...
argcxiang's first blog
Hello, there is argcxiang, I am testing my blog on GitHub! I come from Wuhan University, majoring in Information Security, and I am interesting with some technology skills. The reason why I created this Blog is to record some experience in coding exercise, which is for next year’s summer camp, I hope all we can enter to our dream school. Thanks!