Created
April 26, 2018 18:21
-
-
Save m80126colin/0852fa76bf741c4a258840f892033aae to your computer and use it in GitHub Desktop.
An amortised linear-time solution by hashing
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
import Data.Hashable | |
import Data.HashSet | |
-- Amortised linear-time by hashing | |
uniqhs :: (Hashable a, Eq a) => HashSet a -> [a] -> [a] | |
uniqhs _ [] = [] | |
uniqhs h (x:xs) = if member x h then uniqhs h xs else x:uniqhs (insert x h) xs | |
nub :: [Int] -> [Int] | |
nub = uniqhs empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Amortised linear-time POGGERS