File tree 3 files changed +55
-0
lines changed
solution/0100-0199/0137.Single Number II
3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,26 @@ public:
122
122
};
123
123
```
124
124
125
+ ### **Swift**
126
+
127
+ ```swift
128
+ class Solution {
129
+ func singleNumber(_ nums: [Int]) -> Int {
130
+ var a = nums.sorted()
131
+ var n = a.count
132
+ for i in stride(from: 0, through: n - 1, by: 3) {
133
+ if i == n - 1 {
134
+ return a[i]
135
+ }
136
+ else if a[i] != a[i + 1] {
137
+ return a[i]
138
+ }
139
+ }
140
+ return 0
141
+ }
142
+ }
143
+ ```
144
+
125
145
### ** ...**
126
146
127
147
```
Original file line number Diff line number Diff line change @@ -101,6 +101,26 @@ public:
101
101
};
102
102
```
103
103
104
+ ### **Swift**
105
+
106
+ ```swift
107
+ class Solution {
108
+ func singleNumber(_ nums: [Int]) -> Int {
109
+ var a = nums.sorted()
110
+ var n = a.count
111
+ for i in stride(from: 0, through: n - 1, by: 3) {
112
+ if i == n - 1 {
113
+ return a[i]
114
+ }
115
+ else if a[i] != a[i + 1] {
116
+ return a[i]
117
+ }
118
+ }
119
+ return 0
120
+ }
121
+ }
122
+ ```
123
+
104
124
### ** ...**
105
125
106
126
```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ func singleNumber( _ nums: [ Int ] ) -> Int {
3
+ var a = nums. sorted ( )
4
+ var n = a. count
5
+ for i in stride ( from: 0 , through: n - 1 , by: 3 ) {
6
+ if i == n - 1 {
7
+ return a [ i]
8
+ }
9
+ else if a [ i] != a [ i + 1 ] {
10
+ return a [ i]
11
+ }
12
+ }
13
+ return 0
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments