- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPivotIndex.java
More file actions
Latest commit
23 lines (21 loc) · 601 Bytes
/
Copy pathPivotIndex.java
File metadata and controls
23 lines (21 loc) · 601 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
publicclassPivotIndex {
publicintpivotIndex(int[] nums) {
intsuml = 0, sumr = 0;
for (inti = 0; i < nums.length; i++)
sumr += nums[i];
for(inti = 0; i < nums.length; i++){
if(suml==sumr-nums[i]) returni;
else
{
suml += nums[i];
sumr -= nums[i];
}
}
return -1;
}
publicstaticvoidmain(String[] args) {
int[] nums = { 1, 7, 3, 6, 5, 6 };
PivotIndexobj = newPivotIndex();
System.out.println(obj.pivotIndex(nums));
}
}