Simple C++ solution
/**\n     * Definition for a binary tree node.\n     * struct TreeNode {\n     *     int val;\n     *     TreeNode *left;\n     *     TreeNode *right;\n     *  
    /**\n     * Definition for a binary tree node.\n     * struct TreeNode {\n     *     int val;\n     *     TreeNode *left;\n     *     TreeNode *right;\n     *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n     * };\n     */\n    class Solution {\n    public:\n        int tryRob(TreeNode* root, int& l, int& r) {\n            if (!root)\n                return 0;\n                \n            int ll = 0, lr = 0, rl = 0, rr = 0;\n            l = tryRob(root->left, ll, lr);\n            r = tryRob(root->right, rl, rr);\n            \n            return max(root->val + ll + lr + rl + rr, l + r);\n        }\n    \n        int rob(TreeNode* root) {\n            int l, r;\n            return tryRob(root, l, r);\n        }\n    };\n\nBasically you want to compare which one is bigger between 1) you + sum of your grandchildren and 2) sum of your children. Personally I like my solution better than the most voted solution because I don't need complex data structures like map.
[]