class Solution {
public int pivotIndex(int[] nums) {
int sum = 0;
int lSum = 0;
for(int num : nums)
sum += num;
for (int i = 0; i < nums.length; i++) {
if(lSum == sum - lSum - nums[i])
return i;
lSum += nums[i];
}
return -1;
}
}
'JAVA > leetcode' 카테고리의 다른 글
[LeetCode] Array - Plus One (0) | 2021.08.06 |
---|---|
[LeetCode] Array - Largest Number At Least Twice of Others (0) | 2021.08.06 |
[LeetCode] Array - Find All Numbers Disappeared in an Array (0) | 2021.08.06 |
[LeetCode Medium] Array - Container With Most Water !! - Two-pointer (0) | 2021.08.06 |
[LeetCode] Array - Sort Array By Parity - Two-pointer (0) | 2021.08.05 |