当前位置: 首页> 汽车> 车展 > 网站快速优化排名推荐_大片网址_网页代码_搜索引擎优化的办法有哪些

网站快速优化排名推荐_大片网址_网页代码_搜索引擎优化的办法有哪些

时间:2025/7/12 9:28:43来源:https://blog.csdn.net/lynyzy/article/details/142634648 浏览次数: 0次
网站快速优化排名推荐_大片网址_网页代码_搜索引擎优化的办法有哪些

654.最大二叉树

力扣题目链接:. - 力扣(LeetCode)

前序递归、循环不变量

class Solution {public TreeNode constructMaximumBinaryTree(int[] nums) {return findmax(nums,0,nums.length);}public TreeNode findmax(int[] nums,int leftindex,int rightindex){if(rightindex==leftindex){return null;}if(rightindex-leftindex==1){return new TreeNode(nums[leftindex]);}int max=nums[leftindex];int maxindex=leftindex;for(int i=leftindex;i<rightindex;i++){if(nums[i]>max){max=nums[i];maxindex=i;}}TreeNode root=new TreeNode(max);root.left=findmax(nums,leftindex,maxindex);root.right=findmax(nums,maxindex+1,rightindex);return root;}
}

617.合并二叉树

力扣题目链接:. - 力扣(LeetCode)​​​​​​

前序递归

class Solution {public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {if(root1==null)return root2;if(root2==null)return root1;root1.val+=root2.val;root1.left=mergeTrees(root1.left,root2.left);root1.right=mergeTrees(root1.right,root2.right);return root1;}
}

700.二叉搜索树中的搜索

力扣题目链接:. - 力扣(LeetCode)

class Solution {public TreeNode searchBST(TreeNode root, int val) {if(root==null){return null;}if(val>root.val){return searchBST(root.right,val);}if(val<root.val){return searchBST(root.left,val);}return root;}
}

98.验证二叉搜索树

力扣题目链接:. - 力扣(LeetCode)

中序递归

class Solution {public boolean isValidBST(TreeNode root) {List<Integer> res=new ArrayList<>();midorder(root,res);for(int i=0;i<res.size()-1;i++){if(res.get(i)>=res.get(i+1)){return false;}}return true;}public void midorder(TreeNode root,List<Integer> res){if(root==null){return;}midorder(root.left,res);res.add(root.val);midorder(root.right,res);}
}

关键字:网站快速优化排名推荐_大片网址_网页代码_搜索引擎优化的办法有哪些

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: