Stack
Key points
ArrayDeque
Front(First) [6, 5, 4, 1, 2, 3] Rear(Last)
Stack push to Front and pop from Front
Queue offer to Rear and poll from Front
Queue offerFirst to Front, pollLast from Rear
Example:
Calculator / evaluate expression
Track at least 3 variables: num1, op1, currNum, {currOp}, {num3} ...
currOp is +/-, or op1 && currOp both are * or /: currNum = eval(num1, op1, currNum)
other cases: currNum = eval(currNum, currOp, num3). Because we don't know whether it is left parenthesis or num3 after currOp, let's push currNum, currOp to stack and do calculation later.
Monotonic Queue problem
Maintain increasing or decreasing sequence.
https://1e9.medium.com/monotonic-queue-notes-980a019d5793
0907. Sum of Subarray Minimums: This is new
Lexicographical order
Find a way to fast forward:
0179. Largest Number: Not lexico order, the customized comparator is key.
Select largest/smallest k number from array
Last updated