Leetcode 205. Isomorphic Strings [Java]

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ส.ค. 2024
  • Checkout how to solve the leetcode isomorphic string question in Java.
    Question URL: leetcode.com/p...
    Please write in the comments below which leetcode problem you want me to solve next.
    And remember, a leetcode a day keeps unemployment away!
    Thanks for watching!
    #leetcode205

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

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

    very good explanation.

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

    how does accesing an element in a char array work I thought you access an array by an integer no using a char?

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

      Each character has its own integer representation. But because it is not an "int" array but a "char" array, accessing an array by a char also works in this case. Each char is mapped to a particular index based on the ascii table mappings. So, on a low level, the compiler would just take a "ch" from "charArray[ch]" and would convert a "ch" to a correct index based on the ascii table.
      Hope I have managed to explain it. Here is a new way for you of doing it :)

  • @user-mg5iw6qu3p
    @user-mg5iw6qu3p ปีที่แล้ว

    Can you explain how an empty char array gets a char element?
    My English is almost as bad as the level of programming, if there was an explanation in the video, please clarify in writing in the answer.

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

    how is "paper" and "title" isomporphic and "badc" and "baba" not isomorphic?

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

      All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.
      So, if in a world 'paper' we map 'p' to 't', it would mean that we would map all letters 'p' to 't'. In 'badc' all the chars are unique but in 'baba' none of them are unique. Because no two characters may map to the same character, 'baba' cannot be isomorphic with 'bads'. Got it?

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

      @@ifelsestatement7803 yes brother. i misunderstood "No two characters may map to the same character". but I don't think your "uniqueness" argument holds true for all cases. Thank You so much.

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

      @@biniteshome1403 You are welcome! . If you still have some doubts and have another example, share it with me and I can try to explain it to you in more detail

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

    Ну все, теперь понятно, а то в описании решения никто не пишет про двойную уникальность символов. Gracias

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

      от автора: "Незачтосиас" )))

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

    Cannot get how it works (sToT[sChar] == 0) -> "f" == 0 , so a string is equal to int :/

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

      Try to run this, see what you get:
      char[] a = new char[256];
      System.out.println(a['a'] == 0);
      a['a'] = 'b';
      System.out.println(a['a'] == 0);
      P.S. so, it's a char, not a String. And yes, because you create an empty char array initially with no data in it. By default, before you populate a data into each index, data at each index is equal to 0. Same as with Integer array, when you create a new array, all the values are equal to 0. However, if it would be a String array, the default value would be null. Read about primitive and not primitive data types in Java and default values for them

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

      @@ifelsestatement7803 this is a 'aha' moment for me. thanks for the enlightenment.

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

    Could you give an advice for a beginner, it was an easy execise but i couldn't manage to do it due of my shit logic i think, how to improve it?

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

      Well, very obvious but working advice would be to keep practising. Just pick up the easiest problems first. Become good at solving them. After that upgrade to the next level and do a bit harder ones and so on. Do a problem yourself first and after that check the forum or some tutorials like this one to figure out the more optimal solution. If you will keep practising, you will notice and learn a lot of patterns over time. Try to make a habit, like solve maybe 5-10 problems a week, depending on how much free time you have and just stick to this habit. Believe me, after two months you see significant results

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

      what im currently doing, im new to leetcode, i try my best to complete these problems even if my solution sounds terrible and slow. and then once i complete it i look for the most effective solutions and try to memorize what was used, and the method. and if i ever get a similar problem in the future i will use the better solution.

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

      @@justanothermind9449 Yes, it's a very good start, keep doing it!

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

      @@ifelsestatement7803 I'll try! Thanks for the advice! 🙂