I'm new in Python, and I don't know what's wrong in my python code. I think it's completely the same with my C++ code (DFS).

Python OLE code:

```
class Solution:
# @param root, a tree node
# @param sum, an integer
# @return a list of lists of integers
def pathSum(self, root, sum):
pathAll = [];
if not root:
return pathAll;
path = [];
def dfs(node, sum, path):
if not node.left and not node.right:
if sum == node.val:
path1 = path;
path1.append(sum);
pathAll.append(path1);
return
path.append(node.val);
if node.left:
dfs(node.left, sum-node.val, path);
if node.right:
dfs(node.right, sum-node.val, path);
path.pop();
dfs(root, sum, path);
return pathAll;
```

Python TLE code:

```
class Solution:
# @param root, a tree node
# @param sum, an integer
# @return a list of lists of integers
def pathSum(self, root, sum):
pathAll = [];
if not root:
return pathAll;
path = [];
def dfs(node, sum, path):
if not node.left and not node.right:
if sum == node.val:
path1 = path;
path1.append(sum);
pathAll.append(path1);
return
path2 = path;
path2.append(node.val);
if node.left:
dfs(node.left, sum-node.val, path2);
if node.right:
dfs(node.right, sum-node.val, path2);
dfs(root, sum, path);
return pathAll;
```

C++ AC code:

```
class Solution {
public:
void dfs(TreeNode *node, int sum, vector<int> &path, vector<vector<int> > &ret)
{
if (!node->left && !node->right)
{
if (node->val == sum)
{
path.push_back(sum);
ret.push_back(path);
path.pop_back();
}
return;
}
path.push_back(node->val);
if (node->left)
dfs(node->left, sum-node->val, path, ret);
if (node->right)
dfs(node->right, sum-node->val, path, ret);
path.pop_back();
}
vector<vector<int> > pathSum(TreeNode *root, int sum) {
vector<vector<int> > ret;
if (!root)
return ret;
vector<int> path;
dfs(root, sum, path, ret);
return ret;
}
};
```