1. 程式人生 > 其它 >#力扣 LeetCode1189. “氣球” 的最大數量 @FDDLC

#力扣 LeetCode1189. “氣球” 的最大數量 @FDDLC

技術標籤:演算法&資料結構

題目描述:

https://leetcode-cn.com/problems/maximum-number-of-balloons/

Java程式碼:

class Solution { //b,a,l2,o2,n
    public int maxNumberOfBalloons(String text) {
        int b=0,a=0,l2=0,o2=0,n=0;
        for(int i=text.length()-1;i>=0;i--){
            char c=text.charAt(i);
            if(c=='b')b++;
            else if(c=='a')a++;
            else if(c=='l')l2++;
            else if(c=='o')o2++;
            else if(c=='n')n++;
        }
        return Math.min(b,Math.min(a,Math.min(l2/2,Math.min(o2/2,n))));
    }
}