topic
1 | 1814. Statistics the number of good pairs in an array |
Thinking
这道题没想到yesHash table,还以为yesDouble pointer。
It has been done for a long time,Unexpectedly,Just look at the problem and solve the problem,I also understand。
总之就yes,好对子其实就yes two i - res(i) The same number!
Word gamesa feeling of:
42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121 。
不就yes 42-res(42) == 97 - res(97) ??
when*cnt[i-res(i)]*When there is no existence,Will return0.
ans += cnt[i-j]
Thus, incnt[i-j]have2次值的hour候才Will return到ansmiddle
becausecnt[i-j]=1hour,yes不会经过ansAssociated
cnt[i-j] += 1
solution:
·ElementnumsW - rev(num[il)
·Calculate the number of times per element
·Calculate the difference between the number of times each time
@Lazy
code show as below:
1 | class Solution: |