Word Pattern Leetcode problem number 290 Solution in JAVA JAVA interview programming playlist: • Interview Programming ... Linkedin: / amrita-bala-a2b79460 #java #interviewquestions #leetcode
Пікірлер: 20
@sathiroy4788 Жыл бұрын
It's logic is almost same that's you already discussed in Isomorphic String problem. Again Thanks a lot.
@TechnosageLearning Жыл бұрын
Yeah..If you learn the logics ...you can solve multiple problems with one logic..
@imtiyazali58947 ай бұрын
This code finally accept all case in leetcode for this question:=> public boolean wordPattern(String pattern, String s) { HashMap hm = new HashMap(); Set set = new HashSet(); String arr[] = s.split(" "); if(pattern.length() != arr.length){ return false; } for(int i=0; i
@sathiroy4788 Жыл бұрын
Thanks for this beautiful explanation.
@raadali3270 Жыл бұрын
Thank you so much mam Great explanation 👍👍👍
@user-jq2qu6dj9f6 ай бұрын
Its not working for "abba" And "dog dog dog dog"
@user-fo3fi1td3j2 ай бұрын
Yes this test case failed
@user-fo3fi1td3j2 ай бұрын
class Solution { public boolean wordPattern(String pattern, String s) { Map map=new HashMap(); String[] arr=s.split(" "); if(pattern.length()!=arr.length) { return false; } for(int i=0; i
@roqyaquran241 Жыл бұрын
Sometimes you have to zoom out to see the whole code, or put it in github it's even better. Thanks anyway
@TechnosageLearning Жыл бұрын
Sure I will start putting codes to github
@a.kgaming23603 ай бұрын
I was about to point it out cuz the regex is given according to the spaces but then saw this comment.
@mdniyazhashmi458 Жыл бұрын
Hello Amrita, I am getting only "false" as output trying the same code. package org.leeetcode.problems; import java.util.HashMap; import java.util.Map; public class WordPattern { public static void main(String[] args) { String pattern="abba"; String str="cat, dog, dog, cat"; System.out.println(isWordPattern(pattern,str)); } private static boolean isWordPattern(String pattern, String s) { String []str= s.split(" "); Map hm = new HashMap(); if(pattern.length()!= str.length) { return false; } for(int i=0;i
@TechnosageLearning Жыл бұрын
Hi Sorry my mistake.. The input String is " cat dog dog cat" If you give this input ,it will work...( since we are splitting the string with whitespaces) Or else you need to change the regex, if you want the same input string String[] arr = s.split( ", ") Thanks for pointing out ! Will edit and upload the video again ! Please try and let me know if that works!
@mdniyazhashmi458 Жыл бұрын
@@TechnosageLearning it works thanks!!!
@TechnosageLearning Жыл бұрын
Added the disclaimer in the video..Thanks again for pointing it out
@Future_software_enginneer3 ай бұрын
how can i become a good software engineer to writing a code
@naveenbarnwal7923 Жыл бұрын
i am getting error in this code
@TechnosageLearning Жыл бұрын
Take the code from git repo i shared and then give it a try
@ramineninagajaswanth6476 Жыл бұрын
hello hi i did it using the same method which u taught in isomorphic strings but it is giving wrong answer would you pls check class Solution { public boolean wordPattern(String pattern, String s) { if(pattern.length()!=s.length()) return false; HashMapl=new HashMap(); s=s.trim(); String a[]=s.split(" "); for(int i=0;i
@nibinvarghese57363 ай бұрын
You should check the pattern length with String array length instead of just original String length you should replace this : f(pattern.length()!=s.length()) return false; with this : if(pattern.length()!=a.length) return false;