There was an error while loading. Please reload this page.
1 parent 5b7280e commit 6a0242bCopy full SHA for 6a0242b
1 file changed
leetcode3/염혜정/3701. Compute Alternating Sum.java
@@ -0,0 +1,13 @@
1
+// 짝수는 더하고 홀수는 빼기
2
+// o(n)
3
+
4
+class Solution {
5
+ public int alternatingSum(int[] nums) {
6
+ int sum = 0;
7
+ for (int i = 0; i<nums.length; i++) {
8
+ if (i%2 == 0) sum += nums[i];
9
+ else sum -= nums[i];
10
+ }
11
+ return sum;
12
13
+}
0 commit comments