FrogJmp
1 |
|
설명
X : 시작 위치
Y : 도착 위치
D : 증가량
X+nD > Y의 n을 구하기
도착위치에서 시작위치를 뺀 후 증가량 D로 나누기
다른 언어의 경우 기본적으로 정수형 연산이기 때문에 나머지가 있으면 몫+1 이지만
javascript는 기본적으로 모든 숫자의 연산이 정수가 아닌 실수형이기 때문에 올림으로 계산하면 됨
코드
1 | function solution(X, Y, D) { |
결과

1 |
|
X : 시작 위치
Y : 도착 위치
D : 증가량
X+nD > Y의 n을 구하기
도착위치에서 시작위치를 뺀 후 증가량 D로 나누기
다른 언어의 경우 기본적으로 정수형 연산이기 때문에 나머지가 있으면 몫+1 이지만
javascript는 기본적으로 모든 숫자의 연산이 정수가 아닌 실수형이기 때문에 올림으로 계산하면 됨
1 | function solution(X, Y, D) { |

1 |
|
배열의 요소를 둘로 나누어 좌측 합과 우측합의 차를 절대값으로 계산하여 가장 작은 값을 찾는다.
좌측은 첫 요소부터 마지막요소를 제외한 나머지 요소의 합까지이며
우측은 첫 요소를 제외한 나머지의 합부터 마지막 요소까지
A[0] = 3
A[1] = 1
A[2] = 2
A[3] = 4
A[4] = 3
일 때,
3+1+2+4+5 = 13 이며,
|3 - (1+2+4+3)| 부터 |(3+1+2+4)-3|까지 이므로
마지막 요소는 좌측의 합이 아니기 때문에 반복문은 A.length-1
1 | function solution(A) { |

1 | An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first place). |
1 | A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired. |
1 | A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. |
Update your browser to view this website correctly. Update my browser now