ausleaf / daily-algorithm

0 stars 0 forks source link

Birthday Cake Candles #7

Open ausleaf opened 5 years ago

ausleaf commented 5 years ago

문제) https://www.hackerrank.com/challenges/birthday-cake-candles/problem

숫자 배열중 최대값의 수를 구하는 문제

풀이) https://github.com/Seoyeong-Kim/daily-algorithm/tree/master/src/main/java/hackerrank/birthdaycakecandles

ausleaf commented 5 years ago
        int result = 1;
        int max = ar[0];

        for(int i = 1; i < ar.length; i++) {
            if(ar[i] == max) {
                result++;
            }
            if(ar[i] > max) {
                max = ar[i];
                result = 1;
            }
        }
        return result;