Initial commit
This commit is contained in:
11
724. Find Pivot Index/724. Find Pivot Index.csproj
Normal file
11
724. Find Pivot Index/724. Find Pivot Index.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>_724._Find_Pivot_Index</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
11
724. Find Pivot Index/Program.cs
Normal file
11
724. Find Pivot Index/Program.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace _724._Find_Pivot_Index
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Solution sol = new Solution();
|
||||
sol.PivotIndex(new int[] { 1,4,2});
|
||||
}
|
||||
}
|
||||
}
|
||||
24
724. Find Pivot Index/Solution.cs
Normal file
24
724. Find Pivot Index/Solution.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _724._Find_Pivot_Index;
|
||||
|
||||
public class Solution
|
||||
{
|
||||
public int PivotIndex(int[] nums)
|
||||
{
|
||||
int[] sumsFromLeft = new int[nums.Length];
|
||||
int[] sumsFromRight = new int[nums.Length];
|
||||
for(int i = 1; i < nums.Length; i++)
|
||||
sumsFromLeft[i] = nums[i - 1] + sumsFromLeft[i - 1];
|
||||
|
||||
for (int i = nums.Length - 2; i >= 0; i--)
|
||||
sumsFromRight[i] = nums[i + 1] + sumsFromRight[i + 1];
|
||||
Console.WriteLine(String.Join(" ", sumsFromLeft));
|
||||
Console.WriteLine(String.Join(" ", sumsFromRight));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user