【leetcode】柠檬水找零

bool lemonadeChange(int* bills, int billsSize){
    int hash[11] = {0},i;
    for (i=0; i<billsSize; i++)
    {
        if (bills[i] == 5) hash[5]++;
        else if (bills[i] == 10) 
        {
            hash[5]--;
            hash[10]++;
        }
        else
        {
            if (hash[10])
            {
                hash[5]--;
                hash[10]--;
            }
            else
                hash[5]-=3;
            
        }
        if (hash[5]<0 || hash[10]<0) return false;
    }
    return true;
}
原文地址:https://www.cnblogs.com/ganxiang/p/13716579.html