야근안하기 위한 개린이 블로그

[1일1알고리즘] 4일차 본문

개발/1일1알고리즘

[1일1알고리즘] 4일차

벨린이 2020. 4. 12. 21:25

각각 비교 포인트를 나타내는 두 정수 배열을 반환 하면 되는 문제

https://www.hackerrank.com/challenges/compare-the-triplets/problem

Sample Input 1

17 28 30
99 16 8

Sample Output 1

2 1

 

<?php

// Complete the compareTriplets function below.
function compareTriplets($a, $b) {
$total = array();
for($i=0;$i<count($a);$i++) {
    if($a[$i] > $b[$i]) {
        $total_a += 1;
    } else {
        $total_a += 0;
    }
    if($a[$i] < $b[$i]) {
        $total_b += 1;
    } else {
        $total_b += 0;
    }
}
array_push($total, $total_a, $total_b);
return $total;
}
Comments