朗致集团面试总结

不知道小伙伴们最近有没有面试朗致集团的,分享一下他家的面试题,让大家有个准备。

提问环节很简单,就问了双向链表的概念和满二叉树的概念。

然后是写代码环节,基本上会出三道题,每道题5分钟左右。

第一道题是实现链表,然后逐渐演变成二叉树,最后给二叉树赋值,顺序是从上到下,从左到右。我当时写的时候有一处写错了,时间紧迫实在没及时找到问题所在。

面试结束后,总结整理代码如下,希望能帮到大家:

java 复制代码
import java.util.LinkedList;

import java.util.Queue;



public class LinkedTable<T> {

private T value;

private LinkedTable father;

private LinkedTable leftChild;

private LinkedTable rightChild;



public T getValue() {

return value;

}



public void setValue(T value) {

this.value = value;

}



public LinkedTable getFather() {

return father;

}



public LinkedTable setFather(LinkedTable father) {

this.father = father;

return this;

}



public LinkedTable getLeftChild() {

return leftChild;

}



public void setLeftChild(LinkedTable leftChild) {

this.leftChild = leftChild;

}



public LinkedTable getRightChild() {

return rightChild;

}



public void setRightChild(LinkedTable rightChild) {

this.rightChild = rightChild;

}



public static LinkedTable createFullTree(int depth) {

if (depth <= 0) {

return null;

}

LinkedTable linkedTable = new LinkedTable();

// todo, set CHIldren

setChildren(linkedTable, depth - 1);

return linkedTable;

}



public static void setValue(LinkedTable node, int[] value) {

Queue<LinkedTable> queue = new LinkedList<>();

queue.offer(node);

int i = 0;

while (!queue.isEmpty() && i < value.length) {

LinkedTable currentNode = queue.poll();

currentNode.setValue(value[i++]);

if (currentNode.leftChild != null) {

queue.offer(currentNode.leftChild);

}

if (currentNode.rightChild != null) {

queue.offer(currentNode.rightChild);

}

}

}



public static void setChildren(LinkedTable father, int depth) {

if (depth > 0) {

father.leftChild = new LinkedTable().setFather(father);

father.rightChild = new LinkedTable().setFather(father);

setChildren(father.leftChild, depth - 1);

setChildren(father.rightChild, depth - 1);

}

}



public static void main(String[] args) {

int[] arr = new int[15];

for (int i = 0; i < arr.length; i++) {

arr[i] = i + 1;

}

LinkedTable fullTree = createFullTree(3);

setValue(fullTree, arr);

System.out.println(fullTree);

}

}

最后祝大家面试顺利。

相关推荐
菜鸡爱玩2 小时前
线性代数矩阵相乘
线性代数·算法·矩阵
devilnumber6 小时前
Java 递归算法 详解 + 核心要点 + 实战运用 + 避坑指南
java·开发语言·算法
‎ദ്ദിᵔ.˛.ᵔ₎7 小时前
双指针、滑动窗口、前缀和、二分查找 算法
算法
顾北顾8 小时前
多头注意力机制
人工智能·深度学习·算法
H178535090968 小时前
SolidWorks_基于草图的实体特征20_特征错误排查
算法·3d建模·solidworks
kyriewen8 小时前
手写 Promise.all、race、any:不到 30 行代码,解决并发异步的所有姿势
前端·javascript·面试
hujinyuan201608 小时前
2025年12月中国电子学会青少年机器人技术等级考试试卷(二级) 真题+答案
人工智能·算法·机器人
bIo7lyA8v9 小时前
算法复杂度评估的实验统计方法与可视化的技术8
算法
李老师讲编程9 小时前
中国电子学会图形化2020.12月Scratch三级考级题
算法·scratch·信息学奥赛·图形化编程·scratch素材
退休倒计时9 小时前
【每日一题】LeetCode 53. 最大子数组和 TypeScript
数据结构·算法·leetcode·typescript