Skip to content

Commit

Permalink
Challenge: Palindrome number
Browse files Browse the repository at this point in the history
  • Loading branch information
lexara-prime-ai committed Aug 31, 2023
1 parent 95113eb commit 6838cfd
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
14 changes: 14 additions & 0 deletions CS CHALLENGES.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 10 additions & 0 deletions Palidrome/Palidrome.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions Palidrome/Palidrome.sln
Original file line number Diff line number Diff line change
@@ -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
80 changes: 80 additions & 0 deletions Palidrome/Program.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}

0 comments on commit 6838cfd

Please sign in to comment.