朗致集团面试总结

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

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

然后是写代码环节,基本上会出三道题,每道题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);

}

}

最后祝大家面试顺利。

相关推荐
省四收割者11 分钟前
Go语言入门(10)-数组
数据结构·经验分享·笔记·vscode·算法·golang
lxmyzzs24 分钟前
【图像算法 - 21】慧眼识虫:基于深度学习与OpenCV的农田害虫智能识别系统
人工智能·深度学习·opencv·算法·yolo·目标检测·计算机视觉
KeithTsui25 分钟前
GCC C语言整数转换的理解(Understanding of Integer Conversions in C with GCC)
c语言·开发语言·算法
泽虞1 小时前
《LINUX系统编程》笔记p3
linux·运维·服务器·c语言·笔记·面试
欧阳小猜2 小时前
深度学习②【优化算法(重点!)、数据获取与模型训练全解析】
人工智能·深度学习·算法
小欣加油2 小时前
leetcode 904 水果成篮
c++·算法·leetcode
有Li3 小时前
CXR-LT 2024:一场关于基于胸部X线的长尾、多标签和零样本疾病分类的MICCAI挑战赛|文献速递-深度学习人工智能医疗图像
论文阅读·人工智能·算法·医学生
君万3 小时前
【LeetCode每日一题】56. 合并区间
算法·leetcode·golang
墩墩同学3 小时前
【LeetCode题解】LeetCode 287. 寻找重复数
算法·leetcode·二分查找
小南家的青蛙3 小时前
LeetCode第55题 - 跳跃游戏
算法·leetcode·职场和发展