Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- func firstUniqChar(_ s: String) -> Int {
- let noRepeat = Set(s)
- var onlyAppearOnceLetterIndex = [Int]()
- for char in noRepeat{
- if s.filter({ $0 == char }).count == 1 {
- let charIndex = s.index(of: char)!.encodedOffset
- onlyAppearOnceLetterIndex.append(charIndex)
- }
- }
- return onlyAppearOnceLetterIndex.isEmpty ? -1 : onlyAppearOnceLetterIndex.min()!
- }
- }
Add Comment
Please, Sign In to add comment