Skip to content

Commit aed611e

Browse files
add 3701
1 parent ff74695 commit aed611e

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions/fourththousand

‎paginated_contents/algorithms/4th_thousand/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| 3913 | [Sort Vowels by Frequency](https://leetcode.com/problems/sort-vowels-by-frequency/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3913.java) | | Easy |
1919
| 3908 | [Valid Digit Number](https://leetcode.com/problems/valid-digit-number/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3908.java) | | Easy |
2020
| 3978 | [Unique Middle Element](https://leetcode.com/problems/unique-middle-element/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3978.java) | | Easy |
21+
| 3701 | [Compute Alternating Sum](https://leetcode.com/problems/compute-alternating-sum/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3701.java) | | Easy |
2122
| 3502 | [Minimum Cost to Reach Every Position](https://leetcode.com/problems/minimum-cost-to-reach-every-position/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3502.java) | | Easy |
2223
| 3491 | [Phone Number Prefix](https://leetcode.com/problems/phone-number-prefix/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3491.java) | | Easy |
2324
| 3477 | [Fruits Into Baskets II](https://leetcode.com/problems/fruits-into-baskets-ii/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3477.java) | | Easy |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
public class _3701 {
4+
public static class Solution1 {
5+
public int alternatingSum(int[] nums) {
6+
int sum = 0;
7+
for (int i = 0; i < nums.length; i++) {
8+
if (i % 2 == 0) {
9+
sum += nums[i];
10+
} else {
11+
sum -= nums[i];
12+
}
13+
}
14+
return sum;
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)