• 문제 링크
Find Pivot Index - LeetCode
Can you solve this real interview question? Find Pivot Index - Given an array of integers nums, calculate the pivot index of this array. The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of
leetcode.com
• 풀이 코드
public class Solution {
public int pivotIndex(int[] nums) {
int l = 0, r = 0;
for (int i : nums) r += i;
for (int i = 0; i < nums.length; l += nums[i++]) if (l == r - l - nums[i]) return i;
return -1;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 733. Flood Fill - Java (0) | 2026.10.06 |
|---|---|
| [LeetCode] 728. Self Dividing Numbers - Java (0) | 2026.10.05 |
| [LeetCode] 717. 1-bit and 2-bit Characters - Java (0) | 2026.10.03 |
| [LeetCode] 709. To Lower Case - Java (0) | 2026.10.02 |
| [LeetCode] 706. Design HashMap - Java (0) | 2026.10.01 |
댓글