Created
July 16, 2020 10:37
-
-
Save TarasShu/cbfff56b21f0912651daf71c96d5ddf4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func isStrangePair(_ str1: String, _ str2: String) -> Bool { | |
if str1.index(after: str1.startIndex) == str2.index(before: str2.endIndex) | |
&& | |
str1.index(before: str1.endIndex) == str2.index(after: str2.startIndex) | |
{ | |
return true | |
} else { | |
return false | |
} | |
func isStrangePair(_ str1: String, _ str2: String) -> Bool { | |
if str1.prefix(1) == str2.suffix(1) | |
&& | |
str1.suffix(1) == str2.prefix(1) | |
{ | |
return true | |
} else if str1.isEmpty || str2.isEmpty { | |
return false | |
} else { | |
return false | |
} | |
} | |
isStrangePair("sparkling", "groups") //➞ true | |
// | |
isStrangePair("bush", "hubris") //➞ false | |
// | |
isStrangePair("", "") //➞ true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment