/*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode(int x) { val = x; }* }*/classSolution{publicintrob(TreeNode root){if(root==null)return0;int[] res=dfs(root);return Math.max(res[0],res[1]);}publicint[]dfs(TreeNode root){int[] temp=newint[2];if(root==null)return temp;int[] l=dfs(root.left);//返回子节点偷或者不偷的最优解int[] r=dfs(root.right);temp[1]=l[0]+r[0]+root.val;//当前节点被偷了,左右节点不能再偷了temp[0]=Math.max(l[0],l[1])+Math.max(r[0],r[1]);//当前节点没有偷,左右节点选择最优的偷法return temp;}}
1、下列变量定义错误的是Dint a;double b4.5;boolean btrue;float f9.8; (9.8f)2、65%32的值是 D 3%53219103、对于一个三位的正整数 n,取出它的十位数字k(k为整型)的表达式是k n / 10 % 10k ( n - n / 100 * 100 )k n % 10k n / 104、下列语句序列执…
githooksby Daniel Deutsch由Daniel Deutsch 使用Githooks改善团队的开发工作流程 (Improve your team’s development workflow with Githooks) Every product that is developed by more than one programmer needs to have some guidelines to harmonize the workflow.由多…
核心指导网络由任务编码器by Bob Berry由Bob Berry 如何在现实世界中与实际用户一起指导您的编码和编码生涯 (How to guide your coding and your coding career with real users, in the real world) Experience drives everything. It’s the basis of our reality. It’s a…
by Luciano Strika通过卢西亚诺斯特里卡(Luciano Strika) Command Magicks:如何使用控制台处理文件和字符串 (Command Magicks: How to Manipulate Files and Strings with the Console) As developers, there are lots of repetitive things we do every day that…