René's URL Explorer Experiment


Title: #716 - Max Stack - LeetCode JavaScript Solutions

Open Graph Title: #716 - Max Stack - LeetCode JavaScript Solutions

X Title: #716 - Max Stack - LeetCode JavaScript Solutions

Description: Design a max stack data structure that supports the stack operations and supports finding the stack's maximum element. Implement the Ma...

Open Graph Description: Design a max stack data structure that supports the stack operations and supports finding the stack's maximum element. Implement the Ma...

X Description: Design a max stack data structure that supports the stack operations and supports finding the stack's maximum element. Implement the Ma...

Keywords:

Opengraph URL: https://leetcodejavascript.com/solutions/max-stack

direct link

Domain: leetcodejavascript.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/max-stack","name":"#716 - Max Stack - LeetCode JavaScript Solutions","description":"Design a max stack data structure that supports the stack operations and supports finding the stack's maximum element. Implement the Ma...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"var MaxStack = function() {\n this.stack = [];\n this.maxHeap = new PriorityQueue((a, b) => a.val === b.val ? b.id - a.id : b.val - a.val);\n this.nodeId = 0;\n this.deleted = new Set();\n};\n\n/**\n* @param {number} x\n* @return {void}\n*/\nMaxStack.prototype.push = function(x) {\n const id = this.nodeId++;\n const node = { val: x, id };\n this.stack.push(node);\n this.maxHeap.enqueue(node);\n};\n\n/**\n* @return {number}\n*/\nMaxStack.prototype.pop = function() {\n this.cleanStack();\n const node = this.stack.pop();\n this.deleted.add(node.id);\n return node.val;\n};\n\n/**\n* @return {number}\n*/\nMaxStack.prototype.top = function() {\n this.cleanStack();\n return this.stack[this.stack.length - 1].val;\n};\n\n/**\n* @return {number}\n*/\nMaxStack.prototype.peekMax = function() {\n this.cleanMaxHeap();\n return this.maxHeap.front().val;\n};\n\n/**\n* @return {number}\n*/\nMaxStack.prototype.popMax = function() {\n this.cleanMaxHeap();\n const maxNode = this.maxHeap.dequeue();\n this.deleted.add(maxNode.id);\n return maxNode.val;\n};\n\n/**\n* @return {void}\n*/\nMaxStack.prototype.cleanStack = function() {\n while (this.stack.length && this.deleted.has(this.stack[this.stack.length - 1].id)) {\n this.stack.pop();\n }\n};\n\n/**\n* @return {void}\n*/\nMaxStack.prototype.cleanMaxHeap = function() {\n while (this.maxHeap.size() && this.deleted.has(this.maxHeap.front().id)) {\n this.maxHeap.dequeue();\n }\n};","keywords":"LeetCode 716, #716 - Max Stack, Hard, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}

authorLeetCodeJavascript.com
og:typearticle
og:imagehttps://leetcodejavascript.com/og-image.jpg
og:site_nameLeetCode JavaScript Solutions
twitter:cardsummary_large_image
twitter:urlhttps://leetcodejavascript.com/solutions/max-stack
twitter:imagehttps://leetcodejavascript.com/og-image.jpg
twitter:creator@joshcrozier
theme-color#1f2937

Links:

LeetCodeJavascript.com https://leetcodejavascript.com/
Star on GitHubhttps://github.com/JoshCrozier/leetcode-javascript
Back to all solutionshttps://leetcodejavascript.com
View on LeetCode https://leetcode.com/problems/max-stack/
View on GitHubhttps://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0716-max-stack.js
Stack https://leetcodejavascript.com/tags/stack
Design https://leetcodejavascript.com/tags/design
Linked List https://leetcodejavascript.com/tags/linked-list
Ordered Set https://leetcodejavascript.com/tags/ordered-set
Doubly-Linked Listhttps://leetcodejavascript.com/tags/doubly-linked-list
Josh Crozierhttps://joshcrozier.com

Viewport: width=device-width,initial-scale=1

Robots: index, follow


URLs of crawlers that visited me.