diff --git "a/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/README.md" index 0a67201958f71..bd133216c1647 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/README.md" @@ -193,6 +193,29 @@ public class Solution { } ``` +#### Swift + +```swift +class Solution { + func firstUniqChar(_ s: String) -> Character { + var count = [Int](repeating: 0, count: 26) + let aAsciiValue = Int(Character("a").asciiValue!) + + for char in s { + count[Int(char.asciiValue!) - aAsciiValue] += 1 + } + + for char in s { + if count[Int(char.asciiValue!) - aAsciiValue] == 1 { + return char + } + } + + return " " + } +} +``` + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/Solution.swift" "b/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/Solution.swift" new file mode 100644 index 0000000000000..3bede9a82792e --- /dev/null +++ "b/lcof/\351\235\242\350\257\225\351\242\23050. \347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/Solution.swift" @@ -0,0 +1,18 @@ +class Solution { + func firstUniqChar(_ s: String) -> Character { + var count = [Int](repeating: 0, count: 26) + let aAsciiValue = Int(Character("a").asciiValue!) + + for char in s { + count[Int(char.asciiValue!) - aAsciiValue] += 1 + } + + for char in s { + if count[Int(char.asciiValue!) - aAsciiValue] == 1 { + return char + } + } + + return " " + } +} \ No newline at end of file