/*** 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…