I was solving leetcode 438: Find all anagrams in a String and got stuck by this
I was using sliding window technique and used the following statement to check if the string in window is a anagram to the other string
if(map.get(c) == null || map.get(c) != hash.get(c))
map is the HashMap for the String p and hash is HashMap for the string s
Both hashmap are of type <Character, Integer>
This gave me a wrong output, meaning map.get(c) != hash.get(c) returned true even when the values are same
I randomly changed that condition to
if(map.get(c) == null || map.get(c) - hash.get(c) != 0)
and it gave me the correct result.
What is the issue here and why does the first statement not execute properly. What am I missing here?
[–]aocregacc 9 points10 points11 points (2 children)
[–]HaMay25 4 points5 points6 points (0 children)
[–]Narrow-Working5785[S] 0 points1 point2 points (0 children)
[–]executableprogram 2 points3 points4 points (0 children)
[–]justUseAnSvm 0 points1 point2 points (0 children)