We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6216fce commit 73f1fb3Copy full SHA for 73f1fb3
290.WordPattern.kt
@@ -0,0 +1,28 @@
1
+/*
2
+https://leetcode.com/problems/word-pattern/description
3
+*/
4
+fun wordPattern(pattern: String, s: String): Boolean {
5
+ val map: MutableMap<String, Char> = HashMap()
6
+ val patternArray = pattern.toCharArray()
7
+ val sArray = s.split(" ")
8
+ if (patternArray.size != sArray.size) {
9
+ return false
10
+ }
11
+
12
+ for (i in sArray.indices) {
13
+ val key = sArray[i]
14
+ val value = patternArray[i]
15
16
+ if (!map.containsKey(key) && !map.containsValue(value)) {
17
+ map[key] = value
18
+ } else if (!map.containsKey(key) && map.containsValue(value)) {
19
20
+ } else {
21
+ if (map[key] != value) {
22
23
24
25
26
27
+ return true
28
+}
0 commit comments