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
very good explanation.
Thanks a lot!
how does accesing an element in a char array work I thought you access an array by an integer no using a char?
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 :)
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.
how is "paper" and "title" isomporphic and "badc" and "baba" not isomorphic?
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?
@@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.
@@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
Ну все, теперь понятно, а то в описании решения никто не пишет про двойную уникальность символов. Gracias
от автора: "Незачтосиас" )))
Cannot get how it works (sToT[sChar] == 0) -> "f" == 0 , so a string is equal to int :/
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
@@ifelsestatement7803 this is a 'aha' moment for me. thanks for the enlightenment.
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?
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
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.
@@justanothermind9449 Yes, it's a very good start, keep doing it!
@@ifelsestatement7803 I'll try! Thanks for the advice! 🙂