Skip to content

Commit 0116b52

Browse files
committed
4020. Elevator Requests I4020. Elevator Requests I
1 parent d9a9a0e commit 0116b52

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
3+
1. 아이디어 : 각 배열 숫자의 차이의 절댓값 더하기 Math.abs(requests[i]-requests[i-1]) + requests[0] (첫번째 층까지 올라가는 층수)
4+
5+
2. 시간복잡도 : O(N)
6+
7+
3. 자료구조/알고리즘 : 완전탐색
8+
9+
*/
10+
11+
class Solution {
12+
public int elevatorRequests(int n, int[] requests) {
13+
int ans = 0;
14+
for(int i=1; i<requests.length; i++) ans+=Math.abs(requests[i]-requests[i-1]);
15+
16+
return ans+requests[0];
17+
}
18+
}

0 commit comments

Comments
 (0)