Make Unreal REAL.
article thumbnail
Level 0. 연속된 수의 합

 

 

#include <iostream>
#include <vector>

using namespace std;

vector<int> solution(int num, int total)
{
    vector<int> answer(num, total / num - (num - 1) / 2);

    for (int i = 0; i < num; ++i)
        answer[i] += i;

    return answer;
}

 

시작 = 평균 - (개수 - 1) / 2

 

시작 값을 num 개수만큼 만들고 index 별로 증가시켜준다.

'자료구조 & 알고리즘 > 프로그래머스' 카테고리의 다른 글

Level 0. 평행  (1) 2023.01.24
Level 0. 최빈값 구하기  (0) 2023.01.23
Level 0. 다음에 올 숫자  (0) 2023.01.22
Level 0. 종이 자르기  (0) 2023.01.20
Level 0. 캐릭터의 좌표  (0) 2023.01.19
profile

Make Unreal REAL.

@diesuki4

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

검색 태그