Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Min-Stack Optimized Solution Via JS

function last(stack){
    return stack[stack.length - 1]
}
class MinStack {
    constructor(){
        this.stack = []
        this.minStack = []
    }
push(x){
        if(this.minStack.length === 0 || x <= last(this.minStack)){
            this.minStack.push(x)
        }
        this.stack.push(x)
    }
    
    pop(){
        if(last(this.minStack) === last(this.stack)){
            this.minStack.pop()
        }
        return this.stack.pop()
    }
    
    top(){
        return last(this.stack)
    }
    
    getMin(){
        return last(this.minStack)
    }
    
    
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: page redirect after load 
Javascript :: google maps autocomplete js events 
Javascript :: scrapy javascript 
Javascript :: joi validation 
Javascript :: event loop 
Javascript :: ERESOLVE could not resolve npm ERR! npm ERR! While resolving: @agm/core@1.1.0 npm ERR! Found: @angular/common@10.0.14 
Javascript :: discord.js how to send a message to all guilds 
Javascript :: javascript toPrecision() Method 
Javascript :: Function used to reload the portion of a page using javascript 
Javascript :: jquery add table row 
Javascript :: how to add data to file json in python 
Javascript :: isnan javascript 
Javascript :: Date gethours js 
Javascript :: find and replace value in array of objects javascript 
Javascript :: datatable numbering 
Javascript :: bootstrap 4 navbar-collapse not working angular 
Javascript :: how to select div js 
Javascript :: javascript make alert sound 
Javascript :: javascript if shorthand 
Javascript :: javascript blob to file 
Javascript :: set span text jquery 
Javascript :: json array 
Javascript :: hover con js 
Javascript :: javascript to remove few items from array 
Javascript :: passing livewire variable in alpine js 
Javascript :: round js 
Javascript :: bodyparser deprecated vscode 
Javascript :: get id from queryselector 
Javascript :: check jquery page 
Javascript :: convert date to string javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =