class Solution {
public:
bool isSameTree(TreeNode *p, TreeNode *q) {
if(p==NULL && q==NULL) return true;
if(p==NULL  q==NULL) return false;
if(p>val == q>val)
return isSameTree(p>left,q>left) && isSameTree(p>right,q>right);
return false;
}
};
Same tree (checking whether given two trees are similar or not)

The first test, for "p==NULL && q==NULL" could just be p==q. This is true when both are null, as well as when both are the same nonnull tree  in which case, returning true is much faster than recursing.
It's easier to follow if your last test, for "p>val == q>val", is flipped to "p>val != q>val", along with flipping the returns. The lack of brackets and elses made me think at first that the last return was unreachable code. (Also, although out of scope here, putting the recursion in the last statement is better for tailcall optimization.)
class Solution { public: bool isSameTree(TreeNode *p, TreeNode *q) { if( p == q ) { return true; } if( NULL==p  NULL==q ) { return false; } if( p>val != q>val ) { return false; } return isSameTree( p>left, q>left ) && isSameTree( p>right, q>right ); } }