Runtime complexity of getting the length of a string in different representations
问题 In Swift 2, given a string s , what's the runtime complexity of these statements: s.characters.count s.endIndex s.utf8.count s.utf16.count s.unicodeScalars.count Also, if I know a string contains alphabets only, what's the most efficient way of getting the n-th character? 回答1: OK, I'm trying to answer my own question. Feel free to correct me if I'm wrong. s.characters.count // O(N) s.endIndex // O(1) s.utf8.count // O(N) s.utf16.count // O(N) s.unicodeScalars.count // O(N) Apple's