Non-Linear solutions getting accepted but hashing is showing TLE


#1

class Solution:
# @param A : tuple of integers
# @param B : integer
# @return an integer
def diffPossible(self, A, B):

    if len(A) == 1:
        return 0
    
    if B == 0:
        
        if len(list(A)) != len(set(list(A))) and B == 0:
            return 1
    
        return 0
    
    dic = {}
    for j in A:
        if j not in dic.keys():
            dic[j] = 1
        
        else:
            dic[j] += 1
            
    for i in range(len(A)):
        
        temp = B+A[i]
        dic[A[i]] = 1
        
        if temp in dic.keys() and dic[temp] >= 1:
            return 1
    
    return 0