inblog logo
|
stupefyee
    알고리즘문제풀기

    [JAVA 문제 풀이] 224. 두 정수 사이의 합

    프로그래머스 (12912)
    Stupefyee's avatar
    Stupefyee
    Apr 25, 2025
    [JAVA 문제 풀이] 224. 두 정수 사이의 합
    Contents
    내가 작성한 코드다른 사람의 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/12912
    notion image
     

    내가 작성한 코드

    class Solution { public long solution(int a, int b) { long answer = 0; for(int i = Math.min(a, b); i <= Math.max(a, b); i++) { answer += i; } return answer; } }
     

    다른 사람의 코드

    class Solution { public long solution(int a, int b) { return sumAtoB(Math.min(a, b), Math.max(b, a)); } private long sumAtoB(long a, long b) { return (b - a + 1) * (a + b) / 2; } }
    • 등차수열의 합 공식 이
    Share article
    Contents
    내가 작성한 코드다른 사람의 코드

    stupefyee

    RSS·Powered by Inblog