LeetCode 242. Valid Anagram Solution Explained - Java

preview_player
Показать описание


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

Thanks. You are really good in algorithms..

babumon
Автор

I understand that char 'a' is the ACSII symbol whose value is 97, but how does this

for (int i = 0; i < s.length(); i++) {
characterCount[s.charAt(i) - 'a']++;

characterCount[t.charAt(i) - 'a']--;
}

check for anagrams? Why can't I use any other ACSII symbol char like 'b' or 'c'?

sheriffcrandy
Автор

Thank you Mr. White always appreciated

Kitchen-Raccoon
Автор

very clear and simple solution, thank you!

isaacli
Автор

Can we create StringBuilder for t and start removing one (only) character for each character in s. If StringBuilder is left with zero element then return true.

samj
Автор

I solved it by using two hashmaps and three for loops.... feeling so stupid after seeing this solution 😢

ritchievales
Автор

Hi, when I saw the solution, at first I did not get it until I watched your solution
I solved it with HasMap run time and memory was too high

billynader
Автор

Still confused about the char_count[s.charAt(i)-'a'] and the char_count[t.charAt(i)-'a'];

shiyangnie
Автор

Well one of the easiest solution i came across thank you.

syed_
Автор

Thank you, my friend. That's what I need now to survive.

maksymr.
Автор

Very help full I wish I could support you more than I can

sachitdalwadi
Автор

Starting your video with "this is one of the easiest problems, " tends to be a bit of a turn off. If the problem was easy for your viewers we would not be viewing your tutorial.

philbowden
Автор

would a hashmap be more or less efficient?

debdijmazumder
Автор

Sort them and check if they are equal or not

kathaigal
Автор

the code showing wrong answer when you check for the input rat and car

ronyEdits
Автор

("Hello", "hello") leads to indexOutOfBoundsException. The capital 'H' is the issue here.

ericsodt
Автор

I tried using Hashmap but got me 24ms, time complexity I beleive was O(m+n). that is the best I could do if this is a interview question...LoL. Never would have come up with this solution.

zihaoyan
Автор

Why dont sort both strings and compare if they both r same ..return true if it is else false

Impromptu
Автор

Good solution bad explanation. Where's my Indian guy explaining iteration at?

sanchit
Автор

i think you should have submit the code to see all testcase passed or not

lokanadhamc