Untitled conversation
- User
class Solution { public int rob(TreeNode root) { int ans = 0; ans = Math.max(g(root),f(root)); return ans; } public int f(TreeNode root) { int ans = 0; if(root.left != null){ ans += g(root.left); } if(root.right !=null) { ans += g(root.right); } return ans + root.val; } public int g(TreeNode root){ int ans = 0; if(root.left != null){ ans += Math.max(f(root.left),g(root.left)); } if(root.right !=null) { ans += Math.max(f(root.right),g(root.right)); } return ans ; } }这段代码有什么问题
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.