250x250
Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

devlog_owen

[프로그래머스] 두 정수 사이의 합 본문

algorithm/(js)프로그래머스

[프로그래머스] 두 정수 사이의 합

developer_owen 2023. 11. 6. 17:18
728x90

문제

 

 

 


 

 

나의 풀이

function solution(a, b) {    
  if (a > b) {       						//수의 크기를 a보다 b가 더 크게 설정
    [a, b] = [b, a]; 
  }

  let total = 0;
  for (let num = a; num <= b; num++) {      //for루프로 num변수를 a부터 b까지 반복
    total += num;							//a부터 b까지 total에 누적 합함
  }

  return total;								//total 반환
}

 


 

다른 사람 풀이

 

본문1


 

회고

a,b 크기 할당하는거 [] 대신에 ()해서 시간 오래걸림. 바보.

 


 

 

 

 

728x90