forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path5.java
More file actions
22 lines (18 loc) ยท 653 Bytes
/
5.java
File metadata and controls
22 lines (18 loc) ยท 653 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.*;
class Main {
public static int n = 5; // ๋ฐ์ดํฐ์ ๊ฐ์ N๊ณผ ๋ฐ์ดํฐ ์
๋ ฅ๋ฐ๊ธฐ
public static int arr[] = {10, 20, 30, 40, 50};
public static int[] prefixSum = new int[6];
public static void main(String[] args) {
// ์ ๋์ฌ ํฉ(Prefix Sum) ๋ฐฐ์ด ๊ณ์ฐ
int sumValue = 0;
for (int i = 0; i < n; i++) {
sumValue += arr[i];
prefixSum[i + 1] = sumValue;
}
// ๊ตฌ๊ฐ ํฉ ๊ณ์ฐ(์ธ ๋ฒ์งธ ์๋ถํฐ ๋ค ๋ฒ์งธ ์๊น์ง)
int left = 3;
int right = 4;
System.out.println(prefixSum[right] - prefixSum[left - 1]);
}
}