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
/
Copy path5.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]);
}
}