Improve day 5
This commit is contained in:
@@ -16,11 +16,15 @@ func (stack *Stack) Push(crate byte) {
|
||||
*stack = append(*stack, crate)
|
||||
}
|
||||
|
||||
func (stack *Stack) Pop() byte {
|
||||
func (stack *Stack) Pop() (byte, bool) {
|
||||
last := len(*stack) - 1
|
||||
top := (*stack)[last]
|
||||
*stack = (*stack)[:last]
|
||||
return top
|
||||
if last >= 0 {
|
||||
top := (*stack)[last]
|
||||
*stack = (*stack)[:last]
|
||||
return top, true
|
||||
} else {
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func (stack *Stack) Peek() byte {
|
||||
|
||||
Reference in New Issue
Block a user