写点什么

架构师训练营作业 -Week8

用户头像
wyzwlj
关注
发布于: 2020 年 07 月 27 日

一、判断两个单向链表是否合并和合并时的第一个元素

1、考虑条件:两个链表可能有环;两个链表的长度未知

2、复杂度分析:时间复杂度 O(n+m),空间复杂度 O(n+m)

3、实现算法:

public class Node {    private String data;    private Node next;
public Node(String data, Node next) { this.data = data; this.next = next; }
public String getData() { return data; }
public Node next() { return next; }
public static void main(String[] args) { Node z = new Node("z", null); Node y = new Node("y", z); Node x = new Node("x", y); Node b = new Node("b", x); Node a = new Node("a", b);
Node f = new Node("f", x); Node e = new Node("e", f); Node d = new Node("d", e);

String firstCommonValue = Optional.ofNullable(findFirstCommonNode(a, d)) .map(Node::getData) .orElse(""); System.out.println("第一个公共元素:" + firstCommonValue); }
private static Node findFirstCommonNode(Node head1, Node head2) { Set<Node> nodesOfList1 = new HashSet<>(); Set<Node> nodesOfList2 = new HashSet<>(); Node tmp = head1; while (tmp != null && !nodesOfList1.contains(tmp)) { nodesOfList1.add(tmp); tmp = tmp.next(); }
tmp = head2; while (tmp != null && !nodesOfList2.contains(tmp)) { if (nodesOfList1.contains(tmp)) { return tmp; } nodesOfList2.add(tmp); tmp = tmp.next(); } return null; }}
复制代码


4、其他参考:主要针对链表是否有环的情况进行分析

https://blog.csdn.net/Audience_/article/details/77648916?utm_medium=distribute.pc_feed_404.none-task-blog-BlogCommendFromMachineLearnPai2-3.nonecase&depth_1-utm_source=distribute.pc_feed_404.none-task-blog-BlogCommendFromMachineLearnPai2-3.nonecas


二、DataNode 节点宕机时,HDFS 处理过程的时序图



相关参考:https://xie.infoq.cn/article/9d899bd83e42f81ddf716a5df


用户头像

wyzwlj

关注

还未添加个人签名 2018.05.02 加入

还未添加个人简介

评论

发布
暂无评论
架构师训练营作业 -Week8