当前位置:   article > 正文

朗致集团面试总结_朗致集团逻辑测试题2023

朗致集团逻辑测试题2023

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

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

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

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

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

  1. import java.util.LinkedList;
  2. import java.util.Queue;
  3. public class LinkedTable<T> {
  4. private T value;
  5. private LinkedTable father;
  6. private LinkedTable leftChild;
  7. private LinkedTable rightChild;
  8. public T getValue() {
  9. return value;
  10. }
  11. public void setValue(T value) {
  12. this.value = value;
  13. }
  14. public LinkedTable getFather() {
  15. return father;
  16. }
  17. public LinkedTable setFather(LinkedTable father) {
  18. this.father = father;
  19. return this;
  20. }
  21. public LinkedTable getLeftChild() {
  22. return leftChild;
  23. }
  24. public void setLeftChild(LinkedTable leftChild) {
  25. this.leftChild = leftChild;
  26. }
  27. public LinkedTable getRightChild() {
  28. return rightChild;
  29. }
  30. public void setRightChild(LinkedTable rightChild) {
  31. this.rightChild = rightChild;
  32. }
  33. public static LinkedTable createFullTree(int depth) {
  34. if (depth <= 0) {
  35. return null;
  36. }
  37. LinkedTable linkedTable = new LinkedTable();
  38. // todo, set CHIldren
  39. setChildren(linkedTable, depth - 1);
  40. return linkedTable;
  41. }
  42. public static void setValue(LinkedTable node, int[] value) {
  43. Queue<LinkedTable> queue = new LinkedList<>();
  44. queue.offer(node);
  45. int i = 0;
  46. while (!queue.isEmpty() && i < value.length) {
  47. LinkedTable currentNode = queue.poll();
  48. currentNode.setValue(value[i++]);
  49. if (currentNode.leftChild != null) {
  50. queue.offer(currentNode.leftChild);
  51. }
  52. if (currentNode.rightChild != null) {
  53. queue.offer(currentNode.rightChild);
  54. }
  55. }
  56. }
  57. public static void setChildren(LinkedTable father, int depth) {
  58. if (depth > 0) {
  59. father.leftChild = new LinkedTable().setFather(father);
  60. father.rightChild = new LinkedTable().setFather(father);
  61. setChildren(father.leftChild, depth - 1);
  62. setChildren(father.rightChild, depth - 1);
  63. }
  64. }
  65. public static void main(String[] args) {
  66. int[] arr = new int[15];
  67. for (int i = 0; i < arr.length; i++) {
  68. arr[i] = i + 1;
  69. }
  70. LinkedTable fullTree = createFullTree(3);
  71. setValue(fullTree, arr);
  72. System.out.println(fullTree);
  73. }
  74. }

最后祝大家面试顺利。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/817316
推荐阅读
相关标签
  

闽ICP备14008679号