@msabhi Ya i know its just a variable name, but it is not clear for the reader whether he is using the linkedlist as a queue or stack data structure, or neither.
dianhua1560
@dianhua1560
Posts made by dianhua1560

RE: Simple Java iterative BFS solution with HashMap and queue

RE: My Accepted code with explaination. Does anyone have a better idea?
@pshizhsysu Great summary. Took me some minutes to figure out the if conditions within the postorder while loop:
if (top>left != 0 && top>left != last_pop && top>right != last_pop)
for pushing left child.if (top>right != 0 && top>right != last_pop && (top>left == 0  top>left == last_pop))
for pushing right child.
First, we pop a node out of the stack only when the node is a leaf node or we have already poped the node's left and right children. Secondly, a node can be "looked" at, which is the
TreeNode* top = s.top()
part, at most 3 times: the first time it is looked at.
 got returned back from the left subtree.
 got returned back from the right subtree.
We only add the node's left child when the left child is not
null
and the node is looked at for the very first time. Thus, the firstif
condition includestop>left != last_pop && top>right != last_pop
. Then, we only add the node's right child when the right child is notnull
and the node is looked at when returning from the left subtree or left child isnull
. Thus, the secondif
condition includestop>right != last_pop && (topleft == 0  top>left == last_pop)
. Hope this explanation helps others understand the code better.Thanks.
Edit: We actually don't need the last part of the second
if
condition, simplyif (top>right != 0 && top>right != last_pop)
is enough. 
RE: Short C++/Java/Python, bit different
Neat solution, but i was wondering if the space gonna be an issue if we have many different Strings.

RE: Java O(n) incredibly short yet easy to understand AC solution
@codingcoconut The first derivative of the equation u provided is 2x + 4 and it equals to 0 when x = 2. Since a = 1 that means the parabola opens upward and x = 2 is the coordinate of the bottom point and also the mid point. Anything on the left or right of it has a greater yvalue. Thus, f(1) and f(4), which both are on the right side of f(2), have greater value than f(2). If we use two pointers, one points at the start of the array and one points at the end of it, we will increment or decrement one of the pointers depending which of them has smaller horizontal distance (xcoordinate difference) to the mid point (x = 2 in this case). Since we want descending orders, we will place the smaller one in the array first. Not sure why you are comparing f(1) and f(4) though.

RE: 1 line Ruby, 2 lines Python
@StefanPochmann Got it. Thanks for your replies!

RE: 1 line Ruby, 2 lines Python
@StefanPochmann So the purpose is to illustrate the meaning of this statement? and maybe to avoid overflow?

RE: 1 line Ruby, 2 lines Python
I don't quiet get when you say :
Why minX+maxXx? I actually thought of it as minX+(maxXx), i.e., first the subtraction (maxXx)
Isn't minX+maxXx the same as minX+(maxXx)?

RE: Java O(n) incredibly short yet easy to understand AC solution
Though as simple as the solution is already, we can do less computation if a = 0 and b >= 0 (return original array) and also if a = 0 and b < 0 (return reversed array).

RE: JAVA AC BFS solution
@steve.j.sun Nope we dont... if we just add up the values to pre we still get the same answer.