diff --git "a/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" index be00711a0bbf9..696d6fbb87275 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" @@ -336,6 +336,38 @@ public class CQueue { */ ``` +#### Swift + +```swift +class CQueue { + private var stk1: [Int] = [] + private var stk2: [Int] = [] + + init() { + } + + func appendTail(_ value: Int) { + stk1.append(value) + } + + func deleteHead() -> Int { + if stk2.isEmpty { + while !stk1.isEmpty { + stk2.append(stk1.removeLast()) + } + } + return stk2.isEmpty ? -1 : stk2.removeLast() + } +} + +/** + * Your CQueue object will be instantiated and called as such: + * let obj = CQueue(); + * obj.appendTail(value); + * let param_2 = obj.DeleteHead(); + */ +``` + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.swift" "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.swift" new file mode 100644 index 0000000000000..9d6664ec61f43 --- /dev/null +++ "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.swift" @@ -0,0 +1,20 @@ +class CQueue { + private var stk1: [Int] = [] + private var stk2: [Int] = [] + + init() { + } + + func appendTail(_ value: Int) { + stk1.append(value) + } + + func deleteHead() -> Int { + if stk2.isEmpty { + while !stk1.isEmpty { + stk2.append(stk1.removeLast()) + } + } + return stk2.isEmpty ? -1 : stk2.removeLast() + } +} \ No newline at end of file