Guest User

Untitled

a guest
Jun 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. class Solution {
  2. func firstUniqChar(_ s: String) -> Int {
  3. let noRepeat = Set(s)
  4. var onlyAppearOnceLetterIndex = [Int]()
  5. for char in noRepeat{
  6. if s.filter({ $0 == char }).count == 1 {
  7. let charIndex = s.index(of: char)!.encodedOffset
  8. onlyAppearOnceLetterIndex.append(charIndex)
  9. }
  10. }
  11.  
  12. return onlyAppearOnceLetterIndex.isEmpty ? -1 : onlyAppearOnceLetterIndex.min()!
  13.  
  14. }
  15. }
Add Comment
Please, Sign In to add comment