Skip to content

Instantly share code, notes, and snippets.

@isteshkov
Created July 20, 2022 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isteshkov/32d85cb4d6dd8325c1c4fff910b7b56a to your computer and use it in GitHub Desktop.
Save isteshkov/32d85cb4d6dd8325c1c4fff910b7b56a to your computer and use it in GitHub Desktop.
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