Title: #155 - Min Stack - LeetCode JavaScript Solutions
Open Graph Title: #155 - Min Stack - LeetCode JavaScript Solutions
X Title: #155 - Min Stack - LeetCode JavaScript Solutions
Description: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the MinStack class: MinStack() ...
Open Graph Description: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the MinStack class: MinStack() ...
X Description: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the MinStack class: MinStack() ...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/min-stack
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/min-stack","name":"#155 - Min Stack - LeetCode JavaScript Solutions","description":"Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the MinStack class: MinStack() ...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"var MinStack = function() {\n this.stack = [];\n};\n\n/**\n * @param {number} val\n * @return {void}\n */\nMinStack.prototype.push = function(val) {\n this.stack.push({ val, min: this.stack.length ? Math.min(val, this.getMin()) : val });\n};\n\n/**\n * @return {void}\n */\nMinStack.prototype.pop = function() {\n this.stack.pop();\n};\n\n/**\n * @return {number}\n */\nMinStack.prototype.top = function() {\n return this.stack[this.stack.length - 1].val;\n};\n\n/**\n * @return {number}\n */\nMinStack.prototype.getMin = function() {\n return this.stack.length ? this.stack[this.stack.length - 1].min : 0;\n};","keywords":"LeetCode 155, #155 - Min Stack, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/min-stack |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/min-stack/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0155-min-stack.js |
| Stack | https://leetcodejavascript.com/tags/stack |
| Design | https://leetcodejavascript.com/tags/design |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow