Created
July 20, 2022 06:00
-
-
Save isteshkov/32d85cb4d6dd8325c1c4fff910b7b56a 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
func canConstruct(ransomNote string, magazine string) bool { | |
for _, v := range ransomNote { | |
sym := string(v) | |
ind, exists := searchInString(magazine, sym) | |
if !exists { | |
return false | |
} | |
magazine = magazine[:ind] + magazine[ind+1:] | |
} | |
return true | |
} | |
func searchInString(s string, target string) (int, bool) { | |
for i, r := range s { | |
if string(r) == target { | |
return i, true | |
} | |
} | |
return 0, false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment