MCPcopy Create free account
hub / github.com/Flamewaker/JavaPersonalSummary / push2

Method push2

Code/leetcode/datastructure/MinStack.java:57–62  ·  view source on GitHub ↗

辅助栈和数据栈不同步 (1)辅助栈为空的时候,必须放入新进来的数; (2)新来的数小于或者等于辅助栈栈顶元素的时候,才放入,特别注意这里“等于”要考虑进去,因为出栈的时候,连续的、相等的并且是最小值的元素要同步出栈; (3)出栈的时候,辅助栈的栈顶元素等于数据栈的栈顶元素,才出栈。 总结一下:出栈时,最小值出栈才同步;入栈时,最小值入栈才同步。 @param x

(int x)

Source from the content-addressed store, hash-verified

source not stored for this graph (policy: none)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected