https://leetcode.com/problems/find-pivot-index
Find Pivot Index - LeetCode
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 all the numbers strictly to the index's righ
leetcode.com
솔루션
class Solution:
def pivotIndex(self, nums: List[int]) -> int:
for index, value in enumerate(nums):
if sum(nums[:index+1]) == sum(nums[index:]):
return index
return -1
'컴퓨터공학 & 정보통신 > 알고리즘 문제 풀이' 카테고리의 다른 글
[LeetCode] 989. Add to Array-Form of Integer (0) | 2023.02.15 |
---|---|
[LeetCode] 278. First Bad Version (0) | 2023.02.13 |
[LeetCode] 205. Isomorphic Strings (0) | 2023.02.13 |
[LeetCode] 167. Two Sum II - Input Array Is Sorted (0) | 2023.02.12 |
[LeetCode] 438. Find All Anagrams in a String (0) | 2023.02.12 |