After a solution is accepted it would be very helpful to know how to make it run faster looking at better performing solution(s).
Can leetcode share top performing solution(s) of problems for each supported language ?

int maxDepth(TreeNode* root) { if (root == NULL) return 0; stack<TreeNode*> myStack; stack<int> depthStack; if (root != NULL) myStack.push(root); int maxDepth = 0; depthStack.push(0); while (!myStack.empty()) { TreeNode *p = myStack.top(); int d = depthStack.top(); if (d > maxDepth) maxDepth = d; myStack.pop(); depthStack.pop(); if (p>left != NULL) {myStack.push(p>left); depthStack.push(d + 1);} if (p>right != NULL) {myStack.push(p>right); depthStack.push(d + 1);} } return maxDepth + 1; }

@rainhacker I agree this would be awesome to see (and learn). But the OJ times are very inconsistent, something might score in top 25% on one submission and then submitting the exact same solution a minute later might score in bottom 25%. It's hard to derive much meaning from the OJ times.
I would love to see some actual measurement of the number of cycles or calculations or something not dependent on time or maybe just running your solution 100 times and getting an average may make the number more meaningful. It's not easy to figure out the best way to "measure" a solution quantitatively and in the absence people tend to place a lot of value on the brevity of their solution "3 lines!" which to me doesn't seem to be a good indicator of anything really.

@jdrogin Agree. Since it is an algorithm website, could we at least have a reliable runtime?

@jdrogin
On top of this discussion.
I wonder if the run time is the TOTAL of run time for each individual testcase.
If this is the case (and I believe so), we could just randomly generate some big testcases pools.
Especially for algorithm questions that operations on integers / array of integers / etc.Segmenting the runtime in the bandwidth of 1 ms could be meaning less when you have just a handful of testcases.
I imagine, even with the same time / space complexity, depending on the way people code, the run time could still vary a bit.
And the only way to distinguish would be to have a big pool of testcases.

@Patrick1993 I think this answer is better than mine because I called the recursive function in my return value, which doubles my runtime. Thx

@muzhou @Patrick1993 my solution is very similar to Patrick1993's solution except that I save on one addition by first comparing the values return by recursive call and then only adding to the one that is greatest.
public int maxDepth(TreeNode root) { if (root == null) return 0; int maxL = maxDepth(root.left); int maxR = maxDepth(root.right); if ( maxL > maxR) return maxL + 1; else return maxR + 1; } }
