classTripleInOne{ var arr: [Int] var x: Int var y: Int var z: Int let width:Int init(_stackSize: Int) { width = (stackSize+2) arr = [Int].init(repeating: -1, count: width*3) x =0 y = width z = width*2 } funcpush(_stackNum: Int, _value: Int) { if stackNum ==0 { if x < width -2 { x +=1 arr[x] = value } } elseif stackNum ==1 { if y < width*2-2 { y +=1 arr[y] = value } } else { if z < width*3-2 { z +=1 arr[z] = value } } }
funcpop(_stackNum: Int) -> Int { var res =0 if stackNum ==0 { if x ==0 { res =-1 } else { res = arr[x] arr[x] =-1 x -=1 } } elseif stackNum ==1 { if y == width { res =-1 } else { res = arr[y] arr[y] =-1 y -=1 } } else { if z == width*2 { res =-1 } else { res = arr[z] arr[z] =-1 z -=1 } } return res }