题解 | #第一只公共的牛#

第一只公共的牛

https://www.nowcoder.com/practice/915476a66e714b32b240c3ee9e7ad5fb

/**
 * struct ListNode {
 *	int val;
 *	struct ListNode *next;
 *	ListNode(int x) : val(x), next(nullptr) {}
 * };
 */
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param headA ListNode类 
     * @param headB ListNode类 
     * @param headC ListNode类 
     * @return ListNode类
     */
    ListNode* findIntersection(ListNode* headA, ListNode* headB, ListNode* headC) {
        // write code here
        for (auto p = headA; p != nullptr; p = p->next) {
            cnt[p->val]++;
        }
        for (auto p = headB; p != nullptr; p = p->next) {
            cnt[p->val]++;
        }
        for (auto p = headC; p != nullptr; p = p->next) {
            cnt[p->val]++;
        }
        for (auto p = headA; p != nullptr; p = p->next) {
            if (cnt[p->val] == 3) return p;
        }
        return nullptr;

    }
    map<int, int> cnt = map<int, int>();

};

全部评论

相关推荐

01-06 22:57
武汉大学 Java
点赞 评论 收藏
分享
程序员花海:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
点赞 评论 收藏
分享
2025-12-22 15:04
江西农业大学 Web前端
SaviorSu:直接说下学期可以请假,一般情况学校允许我26届,大三就直接去实习了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务