diff --git a/CS CHALLENGES.sln b/CS CHALLENGES.sln index 58ea566..69fd1bf 100644 --- a/CS CHALLENGES.sln +++ b/CS CHALLENGES.sln @@ -3,6 +3,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fibonacci", "Fibonacci\Fibonacci.csproj", "{F3E46237-F571-4D42-A772-96D8F75ADA22}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Number Operations", "Number Operations\Number Operations.csproj", "{371A9A03-D787-4E30-9604-6480AFB2FD74}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -11,4 +15,14 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F3E46237-F571-4D42-A772-96D8F75ADA22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3E46237-F571-4D42-A772-96D8F75ADA22}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3E46237-F571-4D42-A772-96D8F75ADA22}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3E46237-F571-4D42-A772-96D8F75ADA22}.Release|Any CPU.Build.0 = Release|Any CPU + {371A9A03-D787-4E30-9604-6480AFB2FD74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {371A9A03-D787-4E30-9604-6480AFB2FD74}.Debug|Any CPU.Build.0 = Debug|Any CPU + {371A9A03-D787-4E30-9604-6480AFB2FD74}.Release|Any CPU.ActiveCfg = Release|Any CPU + {371A9A03-D787-4E30-9604-6480AFB2FD74}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection EndGlobal diff --git a/Palidrome/Palidrome.csproj b/Palidrome/Palidrome.csproj new file mode 100644 index 0000000..f02677b --- /dev/null +++ b/Palidrome/Palidrome.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/Palidrome/Palidrome.sln b/Palidrome/Palidrome.sln new file mode 100644 index 0000000..785eac9 --- /dev/null +++ b/Palidrome/Palidrome.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Palidrome", "Palidrome.csproj", "{55BF593D-054D-444A-8DD7-F466D53CCC31}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {55BF593D-054D-444A-8DD7-F466D53CCC31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {55BF593D-054D-444A-8DD7-F466D53CCC31}.Debug|Any CPU.Build.0 = Debug|Any CPU + {55BF593D-054D-444A-8DD7-F466D53CCC31}.Release|Any CPU.ActiveCfg = Release|Any CPU + {55BF593D-054D-444A-8DD7-F466D53CCC31}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {06A95428-639A-46F3-A202-95A9C0E04FF1} + EndGlobalSection +EndGlobal diff --git a/Palidrome/Program.cs b/Palidrome/Program.cs new file mode 100644 index 0000000..0e097d7 --- /dev/null +++ b/Palidrome/Program.cs @@ -0,0 +1,80 @@ +/* +*** Source: LeetCode *** + +Given an integer x, return true if x is a +palindrome +, and false otherwise. + +* Example 1: + +Input: x = 121 +Output: true +> Explanation: 121 reads as 121 from left to right and from right to left. + +* Example 2: + +Input: x = -121 +Output: false + +> Explanation: From left to right, it reads -121. +> From right to left, it becomes 121-. Therefore it is not a palindrome. +> Example 3: + +Input: x = 10 +Output: false + +> Explanation: Reads 01 from right to left. Therefore it is not a palindrome. + +Author: Irfan Ghat + + */ + +class Program +{ + public static void Main(string[] args) + { + Solution solution = new(); + solution.IsPalindrome(200); + } +} + +public class Solution +{ + public static string? reversedInput; + public static string? parsedInput; + + public bool IsPalindrome(int x) + { + // Check if x is < 0 + if (x < 0) + { + return false; + } + else + { + // Convert input to string + parsedInput = x.ToString(); + + if (parsedInput.Length >= 0) + { + // Convert string to array + char[] chars = parsedInput.ToCharArray(); + + // Reverse the array + Array.Reverse(chars); + + // Create a new string from the array + reversedInput = new(chars); + } + // Check if both strings are equal + if (parsedInput == reversedInput) + { + return true; + } + else + { + return false; + } + } + } +} \ No newline at end of file