LeetCode Problem 724. Find Pivot Index || Java Solution Walkthrough

preview_player
Показать описание
LeetCode is a great platform for people who want general coding practice, whether that be for interviews or just wanting to practice their problem solving. I will be taking you through all the steps of finding the optimal solution to each problem on the site following a logical ordering setout by LeetCode themselves.

In this video, we are going over the problem 724. Find Pivot Index, where the goal is to loop through the array, keeping track of the total count of all the elements on the left and right of a so called pivot point, and return the left most index we find where both side are equal.

This problem can be a little bit confusing, because when they say strictly left and strictly right, they mean that the index you are currently on does not count at all towards either sides counts, this is why the sum of left of index 0 is 0 and the sum of right on index length - 1 is also zero. The optimal solution for this problem on leetcode takes two parts, we first must find the sum of all the elements in the array, then we must loop through and determin when the left sum minus the right sum is equal.

~~~ Stay Up To Date With My Social Media ~~~

#unknownkoder #leetcode #algorithms
Рекомендации по теме