From 08aabe94cdbb4f11cbae7427f7778d9a5a2d1e41 Mon Sep 17 00:00:00 2001 From: Alex Prudhomme Date: Sun, 15 Jan 2023 20:23:28 -0500 Subject: [PATCH] Create: 0724-find-pivot-index.cs --- csharp/0724-find-pivot-index.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 csharp/0724-find-pivot-index.cs diff --git a/csharp/0724-find-pivot-index.cs b/csharp/0724-find-pivot-index.cs new file mode 100644 index 000000000..8365c8228 --- /dev/null +++ b/csharp/0724-find-pivot-index.cs @@ -0,0 +1,18 @@ +public class Solution { + public int PivotIndex(int[] nums) { + int total = nums.Sum(); + + int leftSum = 0; + + for (int i = 0; i < nums.Length; i++) + { + if (leftSum == total - leftSum - nums[i]) + { + return i; + } + + leftSum += nums[i]; + } + return -1; + } +} \ No newline at end of file