Skip to content

Instantly share code, notes, and snippets.

@def-
Created March 25, 2016 14:04
Show Gist options
  • Save def-/d15148ea575371204890 to your computer and use it in GitHub Desktop.
Save def-/d15148ea575371204890 to your computer and use it in GitHub Desktop.
# Naive
proc containsAll(letters, text: string): bool =
for c in letters:
if c notin text:
return false
return true
# Only check each letter once
proc containsAll2(letters, text: string): bool =
var chars: set[char]
for c in letters:
if c notin chars:
if c notin text:
return false
chars.incl(c)
return true
echo containsAll("aaa", "asd")
echo containsAll("bbb", "asd")
echo containsAll2("aaa", "asd")
echo containsAll2("bbb", "asd")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment