Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 3f3e7bb

Browse files
author
cd155
committed
add 1.2 implement dictionary
1 parent 47114f3 commit 3f3e7bb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Array.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module Array where
2+
import Data.Map (Map, insert, member, adjust, empty)
23

34
{-
45
1.1
@@ -37,3 +38,18 @@ isUniqBFHelper c (x:xs) = (c /= x) && isUniqBFHelper c xs
3738
3839
final: r1 && r2
3940
-}
41+
42+
{-
43+
1.2
44+
Given two strings, write a method to decide if two string have
45+
the set with the other.
46+
-}
47+
48+
isPerm :: String -> String -> Bool
49+
isPerm xs ys = convToDict xs empty == convToDict ys empty
50+
51+
convToDict :: String -> Map Char Int -> Map Char Int
52+
convToDict [] dict = dict
53+
convToDict (x:xs) dict
54+
| x `member` dict = convToDict xs (adjust (1+) x dict)
55+
| otherwise = convToDict xs (insert x 1 dict)

0 commit comments

Comments
 (0)