@Acekkkkkkkkk Because you may repeatedly subtract variable "match" by mistake. For example,

s = "abcaa"
p = "aa"

According to the program, hashmap should be 'a' : 2. When the value of "match" equals the size of hashmap, which is 1 in this case, we can use result.add().

When i == 0, hashmap become 'a' : 1. When i == 1, hashmap is still 'a' : 1. When i == 2, i>=p.length, hashmap become 'a' : 2. And then if your condition is map.get(c)!=0, match will become -1.

So here is the problem, "match" actually means the number of one letter, like 'a' in string p, is there the same number of letter 'a' in string s in the length of p. Its value(domain) is either 1 or 0. 1 means yes, the number is matched while 0 means no. ( Don't confuse "match" with hashmap 'a').