File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -336,6 +336,38 @@ public class CQueue {
336
336
*/
337
337
```
338
338
339
+ #### Swift
340
+
341
+ ``` swift
342
+ class CQueue {
343
+ private var stk1: [Int ] = []
344
+ private var stk2: [Int ] = []
345
+
346
+ init () {
347
+ }
348
+
349
+ func appendTail (_ value : Int ) {
350
+ stk1.append (value)
351
+ }
352
+
353
+ func deleteHead () -> Int {
354
+ if stk2.isEmpty {
355
+ while ! stk1.isEmpty {
356
+ stk2.append (stk1.removeLast ())
357
+ }
358
+ }
359
+ return stk2.isEmpty ? -1 : stk2.removeLast ()
360
+ }
361
+ }
362
+
363
+ /**
364
+ * Your CQueue object will be instantiated and called as such:
365
+ * let obj = CQueue();
366
+ * obj.appendTail(value);
367
+ * let param_2 = obj.DeleteHead();
368
+ */
369
+ ```
370
+
339
371
<!-- tabs:end -->
340
372
341
373
<!-- solution:end -->
Original file line number Diff line number Diff line change
1
+ class CQueue {
2
+ private var stk1 : [ Int ] = [ ]
3
+ private var stk2 : [ Int ] = [ ]
4
+
5
+ init ( ) {
6
+ }
7
+
8
+ func appendTail( _ value: Int ) {
9
+ stk1. append ( value)
10
+ }
11
+
12
+ func deleteHead( ) -> Int {
13
+ if stk2. isEmpty {
14
+ while !stk1. isEmpty {
15
+ stk2. append ( stk1. removeLast ( ) )
16
+ }
17
+ }
18
+ return stk2. isEmpty ? - 1 : stk2. removeLast ( )
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments