```
class Solution {
public:
bool hasPathSum(TreeNode* root, int sum) {
if(root==NULL) return false;
sum -= root->val;
if(root->left==NULL && root->right==NULL && sum==0) return true;
return hasPathSum(root->left, sum) || hasPathSum(root->right, sum);
}
};
```

This looks like the same algorithm that others are using and people say that they are doing it in 1ms in Java, but why is mine taking 12ms?