We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
template <typename T> void StackWithMin<T>::push(const T& value) { // 把新元素添加到辅助栈 m_data.push(value); // 当新元素比之前的最小元素小时,把新元素插入辅助栈里; // 否则把之前的最小元素重复插入辅助栈里 // jun: 除非当前元素小于或等于min,否则不插入辅助栈 if(m_min.size() == 0 || value <= m_min.top()) m_min.push(value); // else // m_min.push(m_min.top()); } template <typename T> void StackWithMin<T>::pop() { assert(m_data.size() > 0 && m_min.size() > 0); if( m_data.top() == m_min.top() ) { m_min.pop(); } }
这样更加节省空间一点,逻辑判断应该也还好吧
The text was updated successfully, but these errors were encountered:
嗯嗯,leetcode155 最小栈,有些人就用的这种方法,节约点空间。 你那个 pop的时候只pop了栈m_min,漏掉了m_data栈。
Sorry, something went wrong.
No branches or pull requests
这样更加节省空间一点,逻辑判断应该也还好吧
The text was updated successfully, but these errors were encountered: