inblog logo
|
sxias
    Programmers_CT

    [Programmers_CT] 40. 등차수열의 특정한 항만 더하기

    문정준's avatar
    문정준
    Apr 07, 2025
    [Programmers_CT] 40. 등차수열의 특정한 항만 더하기
    Contents
    1. 문제 설명2. 입출력 예시3. 코드 작성4. 테스트 실행5. 제출 후 채점
     
    💡
    프로그래머스 코딩 테스트 38. 등차수열의 특정한 항만 더하기

    1. 문제 설명

    notion image
     

    제한 사항

    notion image

    2. 입출력 예시

    notion image

    3. 코드 작성

    class Solution { public int solution(int a, int d, boolean[] included) { int answer = 0; for(int i=0;i<included.length;i++) { if(included[i]) answer += (d * i + a); } return answer; } }
    ✏️

    등차수열의 성질

    • for문의 index를 활용하여 included가 true일 때만 값을 더함
      • 등차수열의 n번째 항 S = d*n + a
      • if(included[i]) answer += (d*i + a);

    4. 테스트 실행

    notion image

    5. 제출 후 채점

    notion image
    Share article
    Contents
    1. 문제 설명2. 입출력 예시3. 코드 작성4. 테스트 실행5. 제출 후 채점

    Sxias ㆍ a32176740@gmail.com

    RSS·Powered by Inblog