Skip to content

Commit cddda4b

Browse files
solves partition array into thre parts
1 parent b7929f7 commit cddda4b

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# LeetCode Algorithms
22

3-
![problems-solved](https://img.shields.io/badge/Problems%20Solved-223/2081-1f425f.svg)
4-
![problems-solved-java](https://img.shields.io/badge/Java-223/2081-1abc9c.svg)
3+
![problems-solved](https://img.shields.io/badge/Problems%20Solved-231/2081-1f425f.svg)
4+
![problems-solved-java](https://img.shields.io/badge/Java-231/2081-1abc9c.svg)
55
![problems-solved-python](https://img.shields.io/badge/Python-186/2081-1abc9c.svg)
66
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
77
[![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming)
@@ -271,8 +271,8 @@
271271
| 999 | [Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook) | [![Java](assets/java.png)](src/AvailableCapturesForRook.java) |
272272
| 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters) | [![Java](assets/java.png)](src/FindCommonCharacters.java) |
273273
| 1005 | [Maximize Sum of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations) | [![Java](assets/java.png)](src/MaximizeSumOfArrayAfterKNegations.java) |
274-
| 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberComplement.java) |
275-
| 1010 | [Pairs of Songs With Total Durations Divisible by 60](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60) | |
274+
| 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | [![Java](assets/java.png)](src/NumberComplement.java) |
275+
| 1010 | [Pairs of Songs With Total Durations Divisible by 60](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60) | [![Java](assets/java.png)](src/PartitionArrayIntoThreePartsWithEqualSum.java) |
276276
| 1013 | [Partition Array into Three Parts with equal Sum](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum) | |
277277
| 1018 | [Binary Prefix Divisible by 5](https://leetcode.com/problems/binary-prefix-divisible-by-5) | |
278278
| 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import java.util.Arrays;
2+
3+
public class PartitionArrayIntoThreePartsWithEqualSum {
4+
public boolean canThreePartsEqualSum(int[] array) {
5+
final int totalSum = Arrays.stream(array).sum();
6+
if (totalSum % 3 != 0) return false;
7+
int count = 0;
8+
for (int index = 0, sum = 0; index < array.length - 1 ; index++) {
9+
sum += array[index];
10+
if (sum == totalSum / 3) {
11+
count++;
12+
sum = 0;
13+
}
14+
}
15+
return count >= 2;
16+
}
17+
}

0 commit comments

Comments
 (0)