Determine if a string has all unique characters: Difference between revisions

Content added Content deleted
Line 541: Line 541:
(zip [0 ..] xs))
(zip [0 ..] xs))
where
where
go k [_] mb = mb -- Unique.
go k [_] mb = mb -- Unique
go k xs Nothing = Just (k, xs) -- Duplicate.
go k xs Nothing = Just (k, xs) -- Duplicated
go k xs@(x:_) (Just (c, ys@(y:_))) =
go k xs@(x:_) (Just (c, ys@(y:_)))
if x < y
| x < y = Just (k, xs) -- Earlier duplication
then Just (k, xs) -- Earlier duplicate.
| otherwise = Just (c, ys)
else Just (c, ys)



---------------------------TEST----------------------------
---------------------------TEST----------------------------
Line 566: Line 564:
duplicatedCharIndices_
duplicatedCharIndices_
["", ".", "abcABC", "XYZ ZYX", "1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ"]
["", ".", "abcABC", "XYZ ZYX", "1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ"]



--------------------------DISPLAY--------------------------
--------------------------DISPLAY--------------------------