当前位置: 首页 > news >正文

如何做网站迁移网址seo优化排名

如何做网站迁移,网址seo优化排名,大香蕉网站人人做,b2b网站分类【递归】【回溯】Leetcode 112. 路径总和 113. 路径总和 II 112. 路径总和解法:递归 有递归就有回溯 记得return正确的返回上去 113. 路径总和 II解法 递归 如果需要搜索整棵二叉树,那么递归函数就不要返回值 如果要搜索其中一条符合条件的路径&#xff…

【递归】【回溯】Leetcode 112. 路径总和 113. 路径总和 II

  • 112. 路径总和
    • 解法:递归 有递归就有回溯 记得return正确的返回上去
  • 113. 路径总和 II
    • 解法 递归

如果需要搜索整棵二叉树,那么递归函数就不要返回值
如果要搜索其中一条符合条件的路径,递归函数就需要返回值,因为遇到符合条件的路径了就要及时返回

112. 路径总和

---------------🎈🎈题目链接🎈🎈-------------------
在这里插入图片描述

解法:递归 有递归就有回溯 记得return正确的返回上去

count初始等于targetsum,逐次减,如果到了叶子结点正好count为0,那么就返回true
终止条件:if(root.left = null && root.right = null && count=0){ return true; }

时间复杂度O(N)
空间复杂度O(N)

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {public boolean hasPathSum(TreeNode root, int targetSum) {// 终止条件if(root == null) return false;int count = targetSum-root.val;return help(root,count);}public boolean help(TreeNode root, int count){if(root.left==null && root.right==null && count==0){return true;}if(root.left==null && root.right==null && count!=0){return false;}// 左if(root.left != null){if(help(root.left, count-root.left.val)){return true;}}// 右if(root.right != null){if(help(root.right, count-root.right.val)){return true;}}return false;}}

113. 路径总和 II

---------------🎈🎈题目链接🎈🎈-------------------
在这里插入图片描述

解法 递归

时间复杂度O(N)
空间复杂度O(N)

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {List<List<Integer>> finalresult = new ArrayList<>();public List<List<Integer>> pathSum(TreeNode root, int targetSum) {List<Integer> result = new ArrayList<>();if(root == null) return finalresult;result.add(root.val);helper(root,targetSum-root.val,result);return finalresult;}public void helper(TreeNode root, int count, List<Integer> result){if(root.left == null && root.right==null && count==0){finalresult.add(new ArrayList<>(result)); // 这里千万不能finalresult.add(result) 这就成了添加result的引用,每次都会变}// 左if(root.left != null){result.add(root.left.val);helper(root.left, count-root.left.val,result);result.remove(result.size()-1); // 回溯}// 右if(root.right != null){result.add(root.right.val);helper(root.right,count-root.right.val,result);result.remove(result.size()-1); // 回溯}}
}
http://www.hrbkazy.com/news/39929.html

相关文章:

  • 专门做钱币的网站域名邮箱 400电话
  • 手机网站建设行业分析最近的新闻大事10条
  • 国外大型网站杭州疫情最新情况
  • wordpress需要配置文件江苏seo平台
  • 山西山西省建设厅网站正规的代运营公司
  • 专门做三国战纪的网站叫什么企业营销策划是做什么的
  • 想在土巴兔做装修网站找谁手机网页链接制作
  • 网站首页制作的过程十大骗子教育培训机构
  • 朝阳工商登记大厅seo技术培训广东
  • 嘉兴h5建站seo舆情优化
  • 做amazon当地电信屏蔽了网站网络营销策划推广
  • 网络推广培训视频网店seo排名优化
  • 杨庄网站建设百度的网址是什么
  • 企业独立官方网站网址怎么做百度前三推广
  • angularjs做的网站有哪些东莞网络营销代运营
  • 男人女人做邪恶的事网站微信指数查询
  • 做外国网用哪些网站网络广告策划方案范文
  • 移动网站排名怎么做seo知名公司
  • 用vue.js做网站中文域名交易网站
  • 推广网站优化seo教程上排名seo网站营销公司哪家好
  • 企业商城网站建设方案培训总结怎么写
  • 易企秀怎么做招聘网站超链接产品代理推广方案
  • 网站 建设 维护 公司百度网盘官网登陆入口
  • 嘉兴哪里做网站百度推广时间段在哪里设置
  • 联盟网站做的最好柳州网站建设哪里有
  • 百度优化网站建设百度首页官网
  • 手机影视素材网站大全网络公司推广公司
  • 如果用别人公司信息做网站如何免费自己创建网站
  • 企业网站可以免费做吗seo搜索引擎优化推荐
  • 最超值的锦州网站建设seo兼职