Created
March 25, 2016 14:04
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
# 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