【leetcode】1346. 检查整数及其两倍数是否存在

 

bool checkIfExist(int* arr, int arrSize){
    int hash[12001] = { 0 }, i;
    for (i = 0; i<arrSize; i++){
        if (hash[(arr[i] * 2 + 3000)] || (arr[i] % 2 == 0 && hash[(arr[i] / 2 + 3000)]))
            return true;
        hash[arr[i] + 3000]++;        
    }
    return false;
}

 

posted @ 2020-11-28 20:00  温暖了寂寞  阅读(75)  评论(0编辑  收藏  举报