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 | void change_value(int x, int val) { |
위 소스는 main에서 선언된 변수 x에 값 10을 주고 변수 x와 정수 val 매개변수로 하여 change_value를 호출한 후 change_value에서 x의 값을 val로 변경하는 소스이다.
실행을 하면 change_value에서 x의 값은 20으로 변경되었지만 main에서는 여전히 10이다.
이는 main에서 넘긴 x는 x의 값 10을 의미하기 때문에 이것을 바꾸어도 main의 x는 영향을 받지 않는다.
그래서 Call by Value이다.
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. |
HTML은 Box로 이루어져 있으며 문서의 레이아웃을 계산 할 때 박스 모델에 따라 박스의 사이즈가 달라지게 됨
box의 크기에 영향을 주는 요소는 box의 width, height, border, padding, margin이 됨
1 | <div class="div content">content-box</div> |
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