1 0
Read Time:42 Second

Example 1:

Input: nums = [1,7,3,6,5,6]
Output: 3
Explanation:
The pivot index is 3.
Left sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11
Right sum = nums[4] + nums[5] = 5 + 6 = 11


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 right.

class Solution(object):
    def pivotIndex(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        PIndex=-1
        for i in range(len(nums)):
            pevotIndex=self.calculate(nums[0:i],nums[i+1:],i)
            if pevotIndex==True:
                return i
        return PIndex
            
    def calculate(self,a,b,k):
        if(k==0):
            if sum(b)==0:
                return True
        if sum(a)-sum(b)==0:
            return True
        return False

Wrong Answers 😂

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

About Author

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *