Leetcode_860_柠檬水找零_水题

12/10

水题
class Solution {
    
    
    public boolean lemonadeChange(int[] bills) {
    
    
        int a=0,b=0;//a为5,b为10
        for(int i:bills){
    
    
            if(i==10){
    
    
                if(a==0){
    
    
                    return false;
                }
                a--;
                b++;
            }
            else if(i==20){
    
    
                if(b>=1&&a>=1){
    
    
                    a--;
                    b--;
                }
                else if(a>=3){
    
    
                    a-=3;
                }
                else{
    
    
                    return false;
                }
            }
            else{
    
    
                a++;
            }
        }
        return true;
    }
}

猜你喜欢

转载自blog.csdn.net/HDUCheater/article/details/110947097