We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0dd4da3 commit 85c8f4bCopy full SHA for 85c8f4b
Q-0724 - Find Pivot Index/0724.cpp
@@ -0,0 +1,20 @@
1
+class Solution {
2
+public:
3
+ int pivotIndex(vector<int>& nums) {
4
+
5
+ int sumLeft=0, sumRight=0;
6
7
+ for(int i=0; i<nums.size(); i++)
8
+ sumRight+=nums[i];
9
10
11
+ for(int i=0; i<nums.size(); i++){
12
+ sumRight-=nums[i];
13
+ if(sumLeft==sumRight)
14
+ return i;
15
+ sumLeft+=nums[i];
16
+ }
17
18
+ return -1;
19
20
+};
Q-0724 - Find Pivot Index/0724.py
@@ -0,0 +1,16 @@
+class Solution:
+ def pivotIndex(self, nums: List[int]) -> int:
+ sumLeft=0
+ sumRight=0
+ for i in range(len(nums)):
+ sumRight+=nums[i]
+ sumRight-=nums[i]
+ if(sumLeft==sumRight) :
+ return i
+ sumLeft+=nums[i]
+ return -1
0 commit comments