There was an error while loading. Please reload this page.
1 parent 7efeaa8 commit 70d81f1Copy full SHA for 70d81f1
290_Word Pattern_(17th Jan 2022)/WordPattern.java
@@ -0,0 +1,26 @@
1
+class Solution {
2
+ public boolean wordPattern(String pattern, String s) {
3
+ String[] word=s.split(" ");
4
+ if(word.length!=pattern.length())
5
+ return false;
6
+ HashMap<Character,String> hm=new HashMap<>();
7
+ HashSet<String> hs=new HashSet<>();
8
+
9
+ for(int i=0;i<pattern.length();i++){
10
+ char ch=pattern.charAt(i);
11
+ if(hm.containsKey(ch)){
12
+ if(!word[i].equals(hm.get(ch)))
13
14
+ }
15
+ else{
16
+ if(hs.contains(word[i]))
17
18
19
+ hs.add(word[i]);
20
+ hm.put(ch,word[i]);
21
22
23
24
+ return true;
25
26
+}
0 commit comments