Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- func isIsomorphic(_ s: String, _ t: String) -> Bool {
- let sChars = Array(s)
- let tChars = Array(t)
- var mappingCharCodes = [Character: Character]()
- var backMappingCharCodes = [Character: Character]()
- if s.count == 0 { return true }
- for index in 0 ... (s.count - 1) {
- let sChar = sChars[index]
- let tChar = tChars[index]
- if let mappingTChar = mappingCharCodes[sChar] {
- if tChar != mappingTChar {
- return false
- }
- }else if let mappingSChard = backMappingCharCodes[tChar] {
- if sChar != mappingSChard {
- return false
- }
- }else {
- mappingCharCodes.updateValue(tChar, forKey: sChar)
- backMappingCharCodes.updateValue(sChar, forKey: tChar)
- }
- }
- return true
- }
- }
Add Comment
Please, Sign In to add comment