您的位置:首页 > 新闻 > 热点要闻 > 广州现在算什么风险地区_常用的平面设计软件有哪些_如何设计一个网站页面_公司网站建设多少钱

广州现在算什么风险地区_常用的平面设计软件有哪些_如何设计一个网站页面_公司网站建设多少钱

2025/3/13 8:33:53 来源:https://blog.csdn.net/m0_56545264/article/details/146215691  浏览:    关键词:广州现在算什么风险地区_常用的平面设计软件有哪些_如何设计一个网站页面_公司网站建设多少钱
广州现在算什么风险地区_常用的平面设计软件有哪些_如何设计一个网站页面_公司网站建设多少钱

139. 单词拆分

题目链接:139. 单词拆分 - 力扣(LeetCode)

题目难度:中等

代码:

class Solution {public boolean wordBreak(String s, List<String> wordDict) {HashSet<String> set=new HashSet<>(wordDict);boolean[] valid=new boolean[s.length()+1];valid[0]=true;for(int i=1;i<=s.length();i++){for(int j=0;j<i;j++){if(set.contains(s.substring(j,i))&&valid[j])valid[i]=true;}}return valid[s.length()];}
}

198. 打家劫舍

题目链接:198. 打家劫舍 - 力扣(LeetCode)

题目难度:中等

代码:

class Solution {public int rob(int[] nums) {if(nums.length==1) return nums[0];int[] dp=new int[nums.length];dp[0]=nums[0];dp[1]=Math.max(nums[0],nums[1]);for(int i=2;i<nums.length;i++){dp[i]=Math.max(dp[i-1],dp[i-2]+nums[i]);}return dp[nums.length-1];}
}

213. 打家劫舍 II

题目链接:213. 打家劫舍 II - 力扣(LeetCode)

题目难度:中等

代码:

class Solution {public int rob(int[] nums) {if(nums.length==1) return nums[0];int len = nums.length;return Math.max(robAction(nums,0,len-1),robAction(nums,1,len));}public int robAction(int[] nums,int start,int end){int x = 0, y = 0, z = 0;for (int i = start; i < end; i++) {y = z;z = Math.max(y, x + nums[i]);x = y;}return z;}
}

337. 打家劫舍 III

题目链接:337. 打家劫舍 III - 力扣(LeetCode)

题目难度:中等

代码:

class Solution {public int rob(TreeNode root) {int[] res=robAction(root);return Math.max(res[0],res[1]);}int[] robAction(TreeNode root){int res[]=new int[2];if(root==null)return res;int left[]=robAction(root.left);int right[]=robAction(root.right);res[0]=Math.max(left[0],left[1])+Math.max(right[0],right[1]);res[1]=root.val+left[0]+right[0];return res;}
}

版权声明:

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

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