Last active
May 7, 2023 08:36
-
-
Save KaitoMuraoka/90e7e87701a6105ea2e4f8f0ef9442e4 to your computer and use it in GitHub Desktop.
関数を早めに抜ける
This file contains 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
private func isSimilar(str1: String, str2: String) -> String { | |
var ok: String = "Yes" | |
// 条件1のチェック | |
if (str1.count != str2.count) { | |
ok = "No" | |
return ok | |
} | |
// 条件2のチェック | |
var diffCount = 0 | |
for index in 0..<str1.count { | |
if str1[str1.index(str1.startIndex, offsetBy: index)] != str2[str2.index(str2.startIndex, offsetBy: index)] { | |
diffCount += 1 | |
} | |
} | |
if diffCount != 1 { | |
ok = "No" | |
} | |
return ok | |
} | |
func main() { | |
let array = [ | |
["aruru", "araru"], | |
["aruru", "arara"], | |
["aruru", "aruru"], | |
["algo", "all"], | |
["str", "std"] | |
] | |
for it in array { | |
print(isSimilar(str1: it[0], str2: it[1])) | |
} | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment