From c9916dabad59bdf54bc62f66721e2ee5e7a1ce2e Mon Sep 17 00:00:00 2001 From: Electrominch <64524860+Electrominch@users.noreply.github.com> Date: Tue, 4 Oct 2022 13:40:57 +0300 Subject: [PATCH] Initial commit --- .gitattributes | 2 + .gitignore | 398 ++++++++++++++++++ 1. Two Sum/1. Two Sum.csproj | 11 + 1. Two Sum/Program.cs | 10 + 1. Two Sum/Solution.cs | 19 + .../1480. Running Sum of 1d Array.csproj | 11 + 1480. Running Sum of 1d Array/Program.cs | 10 + 1480. Running Sum of 1d Array/Solution.cs | 19 + .../205. Isomorphic Strings.csproj | 11 + 205. Isomorphic Strings/Program.cs | 10 + 205. Isomorphic Strings/Solution.cs | 37 ++ .../217. Contains Duplicate.csproj | 11 + 217. Contains Duplicate/Program.cs | 10 + 217. Contains Duplicate/Solution.cs | 9 + .../350. Intersection of Two Arrays II.csproj | 11 + 350. Intersection of Two Arrays II/Program.cs | 10 + .../Solution.cs | 9 + .../392. Is Subsequence.csproj | 11 + 392. Is Subsequence/Program.cs | 10 + 392. Is Subsequence/Solution.cs | 27 ++ .../53. Maximum Subarray.csproj | 11 + 53. Maximum Subarray/Program.cs | 10 + 53. Maximum Subarray/Solution.cs | 16 + .../724. Find Pivot Index.csproj | 11 + 724. Find Pivot Index/Program.cs | 11 + 724. Find Pivot Index/Solution.cs | 24 ++ .../88. Merge Sorted Array.csproj | 11 + 88. Merge Sorted Array/Program.cs | 14 + 88. Merge Sorted Array/Solution.cs | 42 ++ Leetcode.sln | 73 ++++ Leetcode/.gitattributes | 2 + Leetcode/.gitignore | 398 ++++++++++++++++++ Leetcode/Leetcode.csproj | 10 + Leetcode/Program.cs | 10 + 34 files changed, 1289 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 1. Two Sum/1. Two Sum.csproj create mode 100644 1. Two Sum/Program.cs create mode 100644 1. Two Sum/Solution.cs create mode 100644 1480. Running Sum of 1d Array/1480. Running Sum of 1d Array.csproj create mode 100644 1480. Running Sum of 1d Array/Program.cs create mode 100644 1480. Running Sum of 1d Array/Solution.cs create mode 100644 205. Isomorphic Strings/205. Isomorphic Strings.csproj create mode 100644 205. Isomorphic Strings/Program.cs create mode 100644 205. Isomorphic Strings/Solution.cs create mode 100644 217. Contains Duplicate/217. Contains Duplicate.csproj create mode 100644 217. Contains Duplicate/Program.cs create mode 100644 217. Contains Duplicate/Solution.cs create mode 100644 350. Intersection of Two Arrays II/350. Intersection of Two Arrays II.csproj create mode 100644 350. Intersection of Two Arrays II/Program.cs create mode 100644 350. Intersection of Two Arrays II/Solution.cs create mode 100644 392. Is Subsequence/392. Is Subsequence.csproj create mode 100644 392. Is Subsequence/Program.cs create mode 100644 392. Is Subsequence/Solution.cs create mode 100644 53. Maximum Subarray/53. Maximum Subarray.csproj create mode 100644 53. Maximum Subarray/Program.cs create mode 100644 53. Maximum Subarray/Solution.cs create mode 100644 724. Find Pivot Index/724. Find Pivot Index.csproj create mode 100644 724. Find Pivot Index/Program.cs create mode 100644 724. Find Pivot Index/Solution.cs create mode 100644 88. Merge Sorted Array/88. Merge Sorted Array.csproj create mode 100644 88. Merge Sorted Array/Program.cs create mode 100644 88. Merge Sorted Array/Solution.cs create mode 100644 Leetcode.sln create mode 100644 Leetcode/.gitattributes create mode 100644 Leetcode/.gitignore create mode 100644 Leetcode/Leetcode.csproj create mode 100644 Leetcode/Program.cs diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..426d76d --- /dev/null +++ b/.gitignore @@ -0,0 +1,398 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml diff --git a/1. Two Sum/1. Two Sum.csproj b/1. Two Sum/1. Two Sum.csproj new file mode 100644 index 0000000..e4d16fe --- /dev/null +++ b/1. Two Sum/1. Two Sum.csproj @@ -0,0 +1,11 @@ + + + + Exe + net6.0 + _1._Two_Sum + enable + enable + + + diff --git a/1. Two Sum/Program.cs b/1. Two Sum/Program.cs new file mode 100644 index 0000000..1650ac8 --- /dev/null +++ b/1. Two Sum/Program.cs @@ -0,0 +1,10 @@ +namespace _1._Two_Sum +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} \ No newline at end of file diff --git a/1. Two Sum/Solution.cs b/1. Two Sum/Solution.cs new file mode 100644 index 0000000..42ae8ed --- /dev/null +++ b/1. Two Sum/Solution.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _1._Two_Sum; + +public class Solution +{ + public int[]? TwoSum(int[] nums, int target) + { + for (int i = 0; i < nums.Length; i++) + for (int j = i+1; j < nums.Length; j++) + if (nums[i] + nums[j] == target) + return new int[] { i, j }; + return null; + } +} diff --git a/1480. Running Sum of 1d Array/1480. Running Sum of 1d Array.csproj b/1480. Running Sum of 1d Array/1480. Running Sum of 1d Array.csproj new file mode 100644 index 0000000..fd6ef95 --- /dev/null +++ b/1480. Running Sum of 1d Array/1480. Running Sum of 1d Array.csproj @@ -0,0 +1,11 @@ + + + + Exe + net6.0 + _1480._Running_Sum_of_1d_Array + enable + enable + + + diff --git a/1480. Running Sum of 1d Array/Program.cs b/1480. Running Sum of 1d Array/Program.cs new file mode 100644 index 0000000..7eb4b6e --- /dev/null +++ b/1480. Running Sum of 1d Array/Program.cs @@ -0,0 +1,10 @@ +namespace _1480._Running_Sum_of_1d_Array +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} \ No newline at end of file diff --git a/1480. Running Sum of 1d Array/Solution.cs b/1480. Running Sum of 1d Array/Solution.cs new file mode 100644 index 0000000..3fb8162 --- /dev/null +++ b/1480. Running Sum of 1d Array/Solution.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _1480._Running_Sum_of_1d_Array; + +public class Solution +{ + public int[] RunningSum(int[] nums) + { + int[] result = new int[nums.Length]; + result[0] = nums[0]; + for(int i = 1; i < nums.Length; i++) + result[i] = nums[i] + result[i-1]; + return result; + } +} diff --git a/205. Isomorphic Strings/205. Isomorphic Strings.csproj b/205. Isomorphic Strings/205. Isomorphic Strings.csproj new file mode 100644 index 0000000..aa79717 --- /dev/null +++ b/205. Isomorphic Strings/205. Isomorphic Strings.csproj @@ -0,0 +1,11 @@ + + + + Exe + net6.0 + _205._Isomorphic_Strings + enable + enable + + + diff --git a/205. Isomorphic Strings/Program.cs b/205. Isomorphic Strings/Program.cs new file mode 100644 index 0000000..82fdd73 --- /dev/null +++ b/205. Isomorphic Strings/Program.cs @@ -0,0 +1,10 @@ +namespace _205._Isomorphic_Strings +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine(new Solution().IsIsomorphic("egg","foo")); + } + } +} \ No newline at end of file diff --git a/205. Isomorphic Strings/Solution.cs b/205. Isomorphic Strings/Solution.cs new file mode 100644 index 0000000..5031c19 --- /dev/null +++ b/205. Isomorphic Strings/Solution.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _205._Isomorphic_Strings; + +public class Solution +{ + public bool IsIsomorphic(string s, string t) + { + Dictionary table = new Dictionary(); + Dictionary antiTable = new Dictionary(); + for(int i = 0; i < s.Length; i++) + { + char source = s[i]; + char to = t[i]; + if (table.ContainsKey(source)) + { + if(table[source] != to) + return false; + } + else + table.Add(source, to); + + if (antiTable.ContainsKey(to)) + { + if (antiTable[to] != source) + return false; + } + else + antiTable.Add(to, source); + } + return true; + } +} diff --git a/217. Contains Duplicate/217. Contains Duplicate.csproj b/217. Contains Duplicate/217. Contains Duplicate.csproj new file mode 100644 index 0000000..e1c1dfc --- /dev/null +++ b/217. Contains Duplicate/217. Contains Duplicate.csproj @@ -0,0 +1,11 @@ + + + + Exe + net6.0 + _217._Contains_Duplicate + enable + enable + + + diff --git a/217. Contains Duplicate/Program.cs b/217. Contains Duplicate/Program.cs new file mode 100644 index 0000000..01f794e --- /dev/null +++ b/217. Contains Duplicate/Program.cs @@ -0,0 +1,10 @@ +namespace _217._Contains_Duplicate +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} \ No newline at end of file diff --git a/217. Contains Duplicate/Solution.cs b/217. Contains Duplicate/Solution.cs new file mode 100644 index 0000000..8bd44e0 --- /dev/null +++ b/217. Contains Duplicate/Solution.cs @@ -0,0 +1,9 @@ +namespace _217._Contains_Duplicate; + +public class Solution +{ + public bool ContainsDuplicate(int[] nums) + { + return nums.ToHashSet().Count != nums.Length; + } +} diff --git a/350. Intersection of Two Arrays II/350. Intersection of Two Arrays II.csproj b/350. Intersection of Two Arrays II/350. Intersection of Two Arrays II.csproj new file mode 100644 index 0000000..18fe2bb --- /dev/null +++ b/350. Intersection of Two Arrays II/350. Intersection of Two Arrays II.csproj @@ -0,0 +1,11 @@ + + + + Exe + net6.0 + _350._Intersection_of_Two_Arrays_II + enable + enable + + + diff --git a/350. Intersection of Two Arrays II/Program.cs b/350. Intersection of Two Arrays II/Program.cs new file mode 100644 index 0000000..3a7d142 --- /dev/null +++ b/350. Intersection of Two Arrays II/Program.cs @@ -0,0 +1,10 @@ +namespace _350._Intersection_of_Two_Arrays_II +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} \ No newline at end of file diff --git a/350. Intersection of Two Arrays II/Solution.cs b/350. Intersection of Two Arrays II/Solution.cs new file mode 100644 index 0000000..ac4bef1 --- /dev/null +++ b/350. Intersection of Two Arrays II/Solution.cs @@ -0,0 +1,9 @@ +namespace _350._Intersection_of_Two_Arrays_II; + +public class Solution +{ + public int[] Intersect(int[] nums1, int[] nums2) + { + + } +} diff --git a/392. Is Subsequence/392. Is Subsequence.csproj b/392. Is Subsequence/392. Is Subsequence.csproj new file mode 100644 index 0000000..bde3737 --- /dev/null +++ b/392. Is Subsequence/392. Is Subsequence.csproj @@ -0,0 +1,11 @@ + + + + Exe + net6.0 + _392._Is_Subsequence + enable + enable + + + diff --git a/392. Is Subsequence/Program.cs b/392. Is Subsequence/Program.cs new file mode 100644 index 0000000..4af92ae --- /dev/null +++ b/392. Is Subsequence/Program.cs @@ -0,0 +1,10 @@ +namespace _392._Is_Subsequence +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} \ No newline at end of file diff --git a/392. Is Subsequence/Solution.cs b/392. Is Subsequence/Solution.cs new file mode 100644 index 0000000..20a2152 --- /dev/null +++ b/392. Is Subsequence/Solution.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _392._Is_Subsequence; + +public class Solution +{ + public bool IsSubsequence(string s, string t) + { + if (s.Length == 0) + return true; + int sIndex = 0; + for(int i = 0; i < t.Length; i++) + { + if (t[i] == s[sIndex]) + { + sIndex++; + if (sIndex >= s.Length) + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/53. Maximum Subarray/53. Maximum Subarray.csproj b/53. Maximum Subarray/53. Maximum Subarray.csproj new file mode 100644 index 0000000..59fcbc5 --- /dev/null +++ b/53. Maximum Subarray/53. Maximum Subarray.csproj @@ -0,0 +1,11 @@ + + + + Exe + net6.0 + _53._Maximum_Subarray + enable + enable + + + diff --git a/53. Maximum Subarray/Program.cs b/53. Maximum Subarray/Program.cs new file mode 100644 index 0000000..6489b0f --- /dev/null +++ b/53. Maximum Subarray/Program.cs @@ -0,0 +1,10 @@ +namespace _53._Maximum_Subarray +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} \ No newline at end of file diff --git a/53. Maximum Subarray/Solution.cs b/53. Maximum Subarray/Solution.cs new file mode 100644 index 0000000..617632e --- /dev/null +++ b/53. Maximum Subarray/Solution.cs @@ -0,0 +1,16 @@ +namespace _53._Maximum_Subarray; + +public class Solution +{ + public int MaxSubArray(int[] nums) + { + int best_sum = int.MinValue; + int current_sum = 0; + foreach(var x in nums) + { + current_sum = Math.Max(x, current_sum + x); + best_sum = Math.Max(best_sum, current_sum); + } + return best_sum; + } +} \ No newline at end of file diff --git a/724. Find Pivot Index/724. Find Pivot Index.csproj b/724. Find Pivot Index/724. Find Pivot Index.csproj new file mode 100644 index 0000000..2449c8c --- /dev/null +++ b/724. Find Pivot Index/724. Find Pivot Index.csproj @@ -0,0 +1,11 @@ + + + + Exe + net6.0 + _724._Find_Pivot_Index + enable + enable + + + diff --git a/724. Find Pivot Index/Program.cs b/724. Find Pivot Index/Program.cs new file mode 100644 index 0000000..7804de2 --- /dev/null +++ b/724. Find Pivot Index/Program.cs @@ -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}); + } + } +} \ No newline at end of file diff --git a/724. Find Pivot Index/Solution.cs b/724. Find Pivot Index/Solution.cs new file mode 100644 index 0000000..e7c1c7b --- /dev/null +++ b/724. Find Pivot Index/Solution.cs @@ -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; + } +} diff --git a/88. Merge Sorted Array/88. Merge Sorted Array.csproj b/88. Merge Sorted Array/88. Merge Sorted Array.csproj new file mode 100644 index 0000000..26201db --- /dev/null +++ b/88. Merge Sorted Array/88. Merge Sorted Array.csproj @@ -0,0 +1,11 @@ + + + + Exe + net6.0 + _88._Merge_Sorted_Array + enable + enable + + + diff --git a/88. Merge Sorted Array/Program.cs b/88. Merge Sorted Array/Program.cs new file mode 100644 index 0000000..364137e --- /dev/null +++ b/88. Merge Sorted Array/Program.cs @@ -0,0 +1,14 @@ +namespace _88._Merge_Sorted_Array +{ + internal class Program + { + static void Main(string[] args) + { + int[] n1 = new int[] { 1, 2, 3, 0, 0, 0 }; + int[] n2 = new int[] { 2,5,6 }; + Solution solution = new Solution(); + solution.Merge(n1, 3, n2, n2.Length); + Console.WriteLine(String.Join(" ", n1)); + } + } +} \ No newline at end of file diff --git a/88. Merge Sorted Array/Solution.cs b/88. Merge Sorted Array/Solution.cs new file mode 100644 index 0000000..75ac69e --- /dev/null +++ b/88. Merge Sorted Array/Solution.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace _88._Merge_Sorted_Array; + +public class Solution +{ + public void Merge(int[] nums1, int m, int[] a2, int n) + { + int[] a1 = new int[m]; + for(int i = 0; i < m; i++) + a1[i] = nums1[i]; + int resIndex = 0; + int a1Index = 0, a2Index = 0; + while (resIndex < nums1.Length) + { + int? n1 = a1Index < a1.Length ? a1[a1Index] : null; + int? n2 = a2Index < a2.Length ? a2[a2Index] : null; + int toWrite = 0; + if (n1 != null && n2 != null) + { + toWrite = Math.Min(n1.Value,n2.Value); + if (n1 < n2) + a1Index++; + else + a2Index++; + } + else if(n1!=null) + { + toWrite = n1.Value; + a1Index++; + } + else if(n2!=null) + { + toWrite = n2.Value; + a2Index++; + } + nums1[resIndex++] = toWrite; + } + } +} diff --git a/Leetcode.sln b/Leetcode.sln new file mode 100644 index 0000000..6672cd0 --- /dev/null +++ b/Leetcode.sln @@ -0,0 +1,73 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32901.215 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "1480. Running Sum of 1d Array", "1480. Running Sum of 1d Array\1480. Running Sum of 1d Array.csproj", "{9B7BDB44-0BFF-412B-A5D6-85D17BCDABF2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "724. Find Pivot Index", "724. Find Pivot Index\724. Find Pivot Index.csproj", "{BC5BBAB9-1773-4CFB-95F3-28B00F1AE9A4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "217. Contains Duplicate", "217. Contains Duplicate\217. Contains Duplicate.csproj", "{E21F0BDF-460A-4B8D-8883-EEA5685944F3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "53. Maximum Subarray", "53. Maximum Subarray\53. Maximum Subarray.csproj", "{E0110066-D8FE-465D-A3FC-E141E80CDCC2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "1. Two Sum", "1. Two Sum\1. Two Sum.csproj", "{F5685CDB-BFC9-46A1-AF6D-15B6045D4643}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "88. Merge Sorted Array", "88. Merge Sorted Array\88. Merge Sorted Array.csproj", "{52F34DF1-C947-43F1-9968-21C5F99E114A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "205. Isomorphic Strings", "205. Isomorphic Strings\205. Isomorphic Strings.csproj", "{0F02F764-E6BC-457A-86C1-03F8ABDD0531}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "392. Is Subsequence", "392. Is Subsequence\392. Is Subsequence.csproj", "{82D9F372-85D0-4293-932D-6F90D4AF9CBD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "350. Intersection of Two Arrays II", "350. Intersection of Two Arrays II\350. Intersection of Two Arrays II.csproj", "{3EDA43F9-22B1-4CFE-9912-031FFAA2200E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9B7BDB44-0BFF-412B-A5D6-85D17BCDABF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B7BDB44-0BFF-412B-A5D6-85D17BCDABF2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B7BDB44-0BFF-412B-A5D6-85D17BCDABF2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B7BDB44-0BFF-412B-A5D6-85D17BCDABF2}.Release|Any CPU.Build.0 = Release|Any CPU + {BC5BBAB9-1773-4CFB-95F3-28B00F1AE9A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BC5BBAB9-1773-4CFB-95F3-28B00F1AE9A4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BC5BBAB9-1773-4CFB-95F3-28B00F1AE9A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BC5BBAB9-1773-4CFB-95F3-28B00F1AE9A4}.Release|Any CPU.Build.0 = Release|Any CPU + {E21F0BDF-460A-4B8D-8883-EEA5685944F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E21F0BDF-460A-4B8D-8883-EEA5685944F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E21F0BDF-460A-4B8D-8883-EEA5685944F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E21F0BDF-460A-4B8D-8883-EEA5685944F3}.Release|Any CPU.Build.0 = Release|Any CPU + {E0110066-D8FE-465D-A3FC-E141E80CDCC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0110066-D8FE-465D-A3FC-E141E80CDCC2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0110066-D8FE-465D-A3FC-E141E80CDCC2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0110066-D8FE-465D-A3FC-E141E80CDCC2}.Release|Any CPU.Build.0 = Release|Any CPU + {F5685CDB-BFC9-46A1-AF6D-15B6045D4643}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F5685CDB-BFC9-46A1-AF6D-15B6045D4643}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F5685CDB-BFC9-46A1-AF6D-15B6045D4643}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F5685CDB-BFC9-46A1-AF6D-15B6045D4643}.Release|Any CPU.Build.0 = Release|Any CPU + {52F34DF1-C947-43F1-9968-21C5F99E114A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {52F34DF1-C947-43F1-9968-21C5F99E114A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {52F34DF1-C947-43F1-9968-21C5F99E114A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {52F34DF1-C947-43F1-9968-21C5F99E114A}.Release|Any CPU.Build.0 = Release|Any CPU + {0F02F764-E6BC-457A-86C1-03F8ABDD0531}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0F02F764-E6BC-457A-86C1-03F8ABDD0531}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0F02F764-E6BC-457A-86C1-03F8ABDD0531}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0F02F764-E6BC-457A-86C1-03F8ABDD0531}.Release|Any CPU.Build.0 = Release|Any CPU + {82D9F372-85D0-4293-932D-6F90D4AF9CBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82D9F372-85D0-4293-932D-6F90D4AF9CBD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82D9F372-85D0-4293-932D-6F90D4AF9CBD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82D9F372-85D0-4293-932D-6F90D4AF9CBD}.Release|Any CPU.Build.0 = Release|Any CPU + {3EDA43F9-22B1-4CFE-9912-031FFAA2200E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3EDA43F9-22B1-4CFE-9912-031FFAA2200E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3EDA43F9-22B1-4CFE-9912-031FFAA2200E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3EDA43F9-22B1-4CFE-9912-031FFAA2200E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4CC0BCE7-4740-4C5D-990B-11428B9F1BD8} + EndGlobalSection +EndGlobal diff --git a/Leetcode/.gitattributes b/Leetcode/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/Leetcode/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/Leetcode/.gitignore b/Leetcode/.gitignore new file mode 100644 index 0000000..426d76d --- /dev/null +++ b/Leetcode/.gitignore @@ -0,0 +1,398 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml diff --git a/Leetcode/Leetcode.csproj b/Leetcode/Leetcode.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/Leetcode/Leetcode.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/Leetcode/Program.cs b/Leetcode/Program.cs new file mode 100644 index 0000000..c7a90e5 --- /dev/null +++ b/Leetcode/Program.cs @@ -0,0 +1,10 @@ +namespace Leetcode +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} \ No newline at end of file