We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a81043d commit 914a2e4Copy full SHA for 914a2e4
java/724-Find-Pivot-Index
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ public int pivotIndex(int[] nums) {
3
+ int totalSum = 0;
4
+ for (int i = 0; i < nums.length; i++) {
5
+ totalSum += nums[i];
6
+ }
7
+ int leftSum = 0;
8
9
+ int rightSum = totalSum - leftSum - nums[i];
10
+ if (leftSum == rightSum) {
11
+ return i;
12
13
+ leftSum += nums[i];
14
15
+ return -1;
16
17
+}
0 commit comments