From 032cffb4171d20ccf7150e54bbea61e0993b77f8 Mon Sep 17 00:00:00 2001 From: Mukesh Kumar <71259159+the-macson@users.noreply.github.com> Date: Sat, 22 Oct 2022 08:54:01 +0530 Subject: [PATCH] created 724_Find_Pivot_Index.cpp file --- LeetCode Solutions/724_Find_Pivot_Index.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LeetCode Solutions/724_Find_Pivot_Index.cpp diff --git a/LeetCode Solutions/724_Find_Pivot_Index.cpp b/LeetCode Solutions/724_Find_Pivot_Index.cpp new file mode 100644 index 00000000..4b4fe6b5 --- /dev/null +++ b/LeetCode Solutions/724_Find_Pivot_Index.cpp @@ -0,0 +1,21 @@ +class Solution { +public: + int pivotIndex(vector& nums) { + vectorarr1; + vectorarr2(nums.size()); + arr1.push_back(0); + arr2[nums.size()-1] = 0; + for(int i = 0; i < nums.size() - 1; i++){ + arr1.push_back(nums[i] + arr1[i]); + } + for(int i = nums.size() - 1; i > 0; i--){ + arr2[i-1] = arr2[i] + nums[i]; + } + for(int i = 0; i < nums.size(); i++){ + if(arr1[i] == arr2[i]){ + return i; + } + } + return -1; + } +}; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy