04 2023 档案
摘要:int pre; boolean isSearchTree(root){ if(root == null){ return true; } if(!isSearchTree(root.left)){ return false; } if(root.val < pre){ return false;
阅读全文
摘要:判断是否对称 recursion(root1,root2){ if(root1 == null && root2 == null){return ture;} if(root1 == null || root2 == null || root1.val != root2.val)return fal
阅读全文
摘要:搜索二叉树:每个节点的左子树的值都小于当前节点,右子树的节点值都大于当前节点。其中序遍历就是一个有序的序列 转化成双向链表,需要记录一下头节点,和前一个节点,将前一个节点和当前节点相连 pre head convert(pRoot){ if(pRoot == null)return null; co
阅读全文
摘要:递归的方法遍历二叉树 最大深度: fun(root){ if(root == null){ return 0; } return (Max(fun(root.left), fun(root.right)) + 1); } 和为某值 fun(root ,sum){ if(root == null){
阅读全文
摘要:1.用一个队列记录当前层的节点,然后一个个取出,取出的同时将取出节点的儿子节点加入到队列中。 2.之字遍历则需要一个标志为将行进行翻转 ArrayList<Integer>(ArrayList<Integer>()) res; flag = true;//实现奇数行翻转,偶数行不翻转 Queue t
阅读全文
摘要:1.给链表加一个头节点 2. 判断后一个节点与后后节点的值是否相等,如果相等就将cur.next = cur.next.next; 继续判断后面的节点是否相等,如果相等,继续将cur.next = cur.next.next; 如果不相同就是cur指针向后移动 具体实现如下 while(cur.ne
阅读全文