Word Pattern | LeetCode problem 290

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ม.ค. 2025

ความคิดเห็น • 20

  • @sathiroy4788
    @sathiroy4788 ปีที่แล้ว +1

    It's logic is almost same that's you already discussed in Isomorphic String problem. Again Thanks a lot.

    • @TechnosageLearning
      @TechnosageLearning  ปีที่แล้ว +2

      Yeah..If you learn the logics ...you can solve multiple problems with one logic..

  • @sathiroy4788
    @sathiroy4788 ปีที่แล้ว

    Thanks for this beautiful explanation.

  • @raadali3270
    @raadali3270 2 ปีที่แล้ว

    Thank you so much mam
    Great explanation 👍👍👍

  • @roqyaquran241
    @roqyaquran241 ปีที่แล้ว +1

    Sometimes you have to zoom out to see the whole code, or put it in github it's even better. Thanks anyway

    • @TechnosageLearning
      @TechnosageLearning  ปีที่แล้ว

      Sure I will start putting codes to github

    • @a.kgaming2360
      @a.kgaming2360 7 หลายเดือนก่อน

      I was about to point it out cuz the regex is given according to the spaces but then saw this comment.

  • @imtiyazali5894
    @imtiyazali5894 11 หลายเดือนก่อน +1

    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

  • @mdniyazhashmi458
    @mdniyazhashmi458 2 ปีที่แล้ว

    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
      @TechnosageLearning  2 ปีที่แล้ว +1

      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
      @mdniyazhashmi458 2 ปีที่แล้ว

      @@TechnosageLearning it works thanks!!!

    • @TechnosageLearning
      @TechnosageLearning  2 ปีที่แล้ว +1

      Added the disclaimer in the video..Thanks again for pointing it out

  • @Future_software_enginneer
    @Future_software_enginneer 8 หลายเดือนก่อน

    how can i become a good software engineer to writing a code

  • @P.RAMANJIREDDY
    @P.RAMANJIREDDY 11 หลายเดือนก่อน +1

    Its not working for "abba" And "dog dog dog dog"

    • @VenkyKunchala-y1c
      @VenkyKunchala-y1c 6 หลายเดือนก่อน

      Yes this test case failed

    • @VenkyKunchala-y1c
      @VenkyKunchala-y1c 6 หลายเดือนก่อน

      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

  • @naveenbarnwal7923
    @naveenbarnwal7923 ปีที่แล้ว

    i am getting error in this code

    • @TechnosageLearning
      @TechnosageLearning  ปีที่แล้ว

      Take the code from git repo i shared and then give it a try

  • @ramineninagajaswanth6476
    @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

    • @nibinvarghese5736
      @nibinvarghese5736 7 หลายเดือนก่อน

      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;