朗致集团面试总结

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

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

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

}

}

最后祝大家面试顺利。

相关推荐
星星的月亮叫太阳20 分钟前
large-scale-DRL-exploration 代码阅读 总结
python·算法
王哈哈^_^33 分钟前
YOLOv11视觉检测实战:安全距离测算全解析
人工智能·数码相机·算法·yolo·计算机视觉·目标跟踪·视觉检测
..Cherry..1 小时前
Etcd详解(raft算法保证强一致性)
数据库·算法·etcd
商汤万象开发者1 小时前
LazyLLM教程 | 第13讲:RAG+多模态:图片、表格通吃的问答系统
人工智能·科技·算法·开源·多模态
Lee_yayayayaya1 小时前
本原多项式产生m序列的原理
算法
拉不动的猪2 小时前
# 关于初学者对于JS异步编程十大误区
前端·javascript·面试
蒙奇D索大2 小时前
【算法】递归的艺术:从本质思想到递归树,深入剖析算法的性能权衡
经验分享·笔记·算法·改行学it
王哈哈^_^2 小时前
【数据集+完整源码】水稻病害数据集,yolov8水稻病害检测数据集 6715 张,目标检测水稻识别算法实战训推教程
人工智能·算法·yolo·目标检测·计算机视觉·视觉检测·毕业设计
light_in_hand3 小时前
内存区域划分——垃圾回收
java·jvm·算法
小安同学iter3 小时前
SQL50+Hot100系列(11.7)
java·算法·leetcode·hot100·sql50