leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0404.cpp (566B)
0 class Solution {
1 public:
2 int sumOfLeftLeaves(TreeNode *root) {
3 if (!root) return 0;
5 int res = 0;
6 stack<TreeNode *> st;
8 st.push(root);
9 while (!st.empty()) {
10 TreeNode *root = st.top();
11 st.pop();
12 if (root->left) {
13 if (!root->left->left && !root->left->right)
14 res += root->left->val;
15 else
16 st.push(root->left);
17 }
18 if (root->right) st.push(root->right);
19 }
20 return res;
21 }
22 };