웅재의 코딩세상

[프로그래머스] 배열 비교하기 본문

코딩테스트/프로그래머스 - LV 0

[프로그래머스] 배열 비교하기

웅드 2024. 1. 29. 17:16

 

 

  • 풀이
#include <string>
#include <vector>
#include <numeric>

using namespace std;

int solution(vector<int> arr1, vector<int> arr2) {
    
    if(arr1.size() < arr2.size()) return -1;
    else if(arr1.size() > arr2.size()) return 1;
    else{
        int sum1 = accumulate(arr1.begin(), arr1.end(),0);
        int sum2 = accumulate(arr2.begin(), arr2.end(),0);
        return sum1 == sum2 ? 0 : sum1 > sum2 ? 1 : -1;
    }
}
반응형