File tree 2 files changed +41
-0
lines changed
2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -193,6 +193,29 @@ public class Solution {
193
193
}
194
194
```
195
195
196
+ #### Swift
197
+
198
+ ``` swift
199
+ class Solution {
200
+ func firstUniqChar (_ s : String ) -> Character {
201
+ var count = [Int ](repeating : 0 , count : 26 )
202
+ let aAsciiValue = Int (Character (" a" ).asciiValue ! )
203
+
204
+ for char in s {
205
+ count[Int (char.asciiValue ! ) - aAsciiValue] += 1
206
+ }
207
+
208
+ for char in s {
209
+ if count[Int (char.asciiValue ! ) - aAsciiValue] == 1 {
210
+ return char
211
+ }
212
+ }
213
+
214
+ return " "
215
+ }
216
+ }
217
+ ```
218
+
196
219
<!-- tabs: end -->
197
220
198
221
<!-- solution: end -->
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ func firstUniqChar( _ s: String ) -> Character {
3
+ var count = [ Int] ( repeating: 0 , count: 26 )
4
+ let aAsciiValue = Int ( Character ( " a " ) . asciiValue!)
5
+
6
+ for char in s {
7
+ count [ Int ( char. asciiValue!) - aAsciiValue] += 1
8
+ }
9
+
10
+ for char in s {
11
+ if count [ Int ( char. asciiValue!) - aAsciiValue] == 1 {
12
+ return char
13
+ }
14
+ }
15
+
16
+ return " "
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments