반응형
반응형
https://school.programmers.co.kr/learn/courses/30/lessons/120923
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
문제 요약
연속된 n개의 수의 합이 total이 되는 수들의 집합을 반환하는 함수 만들기
풀이
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(int num, int total) {
int sum = 0;
int x = 0;
List<int> list = new List<int>();
for (int i = 1; i < num; i++) sum += i;
x = (total - sum) / num;
for (int j = 0; j < num; j++) list.Add(x + j);
return list.ToArray();
}
}
오늘 엄청 부지런하게 보냈음!!
반응형
'Algorithm > Programmers' 카테고리의 다른 글
[C#]프로그래머스 136798 기사단원의 무기 - Hide (0) | 2024.11.29 |
---|---|
[C#]프로그래머스 42586 기능개발 - Hide (0) | 2024.11.27 |
[C#]프로그래머스 135808 과일 장수 - Hide (0) | 2024.11.24 |
[C#]프로그래머스 12921 소수 찾기 - Hide (0) | 2024.11.21 |
[C#]프로그래머스 181846 두 수의 합 - Hide (0) | 2024.11.18 |