I also have a solution in C# using 2 global variables:

* Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNode left; * public TreeNode right; * public TreeNode(int x) { val = x; } * } */ public class Solution { int firstSum = 0; int secondSum = 0; public int Rob(TreeNode root) { Traverse(root, true); return Math.Max(firstSum, secondSum); } private void Traverse(TreeNode node, bool bFirst){ if (node != null){ if (bFirst){ firstSum = firstSum + node.val; } else{ secondSum = secondSum + node.val; } if (node.left != null){ Traverse(node.left, !bFirst); } if (node.right != null){ Traverse(node.right, !bFirst); } } } } ```