classSolution{publicintpivotIndex(int[] nums){Map<Integer,Integer> mapL =newHashMap<>();Map<Integer,Integer> mapR =newHashMap<>();int len = nums.length;int resL =0;int resR =0;for(int i =0; i < len; i++){
mapL.put(i, resL);
resL += nums[i];}for(int i = len -1; i >=0; i--){
mapR.put(i, resR);
resR += nums[i];}for(int i =0; i < len; i++){int a = mapL.get(i);int b = mapR.get(i);if(i < len && a == b){return i;}}return-1;}}
classSolution{publicintpivotIndex(int[] nums){int total =Arrays.stream(nums).sum();int sum =0;for(int i =0; i < nums.length;++i){if(2* sum + nums[i]== total){return i;}
sum += nums[i];}return-1;}}