-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95113eb
commit 6838cfd
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |