朗致集团面试总结

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

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

然后是写代码环节,基本上会出三道题,每道题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 小时前
数据结构与算法-第 3 章 常用算法-贪心算法
数据结构·笔记·python·算法·贪心算法
对空六课2 小时前
指标口径生效时间的版本查询实现
大数据·服务器·前端·算法·数据分析
对空六课2 小时前
RFM分层边界变化的回溯计算
大数据·服务器·前端·数据库·人工智能·算法·数据分析
一勺思维2 小时前
我为什么把 Agent 的核心逻辑从 LangChain 里搬出来手写
算法
碧海银沙音频科技研究院2 小时前
基于炬芯ATS308X的LE aduio LC3编解码算法功能实现
算法
小蒋观天下2 小时前
厂区人员徘徊游荡判别——基于时序轨迹速度的逗留行为分级算法落地
大数据·人工智能·深度学习·算法·机器学习·ai大模型
程序员清风3 小时前
堆与优先队列:从 Top K 到任务调度
java·数据结构·算法
shaibdoio3 小时前
瞬维AI技术拆解:AI获客智能体的双层漏斗算法原理
大数据·人工智能·算法
suhan3 小时前
【数据结构】四、串:串string、模式匹配BF\KMP、广义表
数据结构·后端·算法
程序员Sunday3 小时前
ES Module 和 CommonJS 有什么区别?循环依赖时会发生什么?
前端·javascript·面试