You are viewing a single comment's thread. Return to all comments →
Golang (straightforward solution):
package main import ( "fmt" "os" "io" "bytes" "strings" ) func main() { queue := []string{} var buf bytes.Buffer io.Copy(&buf, os.Stdin) commands := strings.Split(buf.String(),"\n") for i,v := range commands { if i == 0 { continue } steps := strings.Split(v," ") if steps[0] == "1" { queue = append(queue, steps[1]) } if steps[0] == "2" { queue = queue[1:] } if steps[0] == "3" { fmt.Println(queue[0]) } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Queue using Two Stacks
You are viewing a single comment's thread. Return to all comments →
Golang (straightforward solution):