-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisPalindrome.cs
More file actions
43 lines (36 loc) · 1.01 KB
/
isPalindrome.cs
File metadata and controls
43 lines (36 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
namespace treinoObjetos
{
public class Solution
{
public bool IsPalindrome(int x)
{
int len = x.ToString().Length;
int[] arrayNum = new int[len];
int[] revNum = new int[len];
if (x < 0) return false;
for (int i = len - 1; i >= 0; i--)
{
arrayNum[i] = x % 10;
x /= 10;
}
Array.Copy(arrayNum, revNum, arrayNum.Length);
Array.Reverse(revNum);
for (int i = 0; i < len; i++)
{
if (arrayNum[i] != revNum[i])
{
return false;
}
}
return true;
}
static void Main(string[] args)
{
Solution solution = new Solution();
Console.Write("\nDigite um número: ");
int num = int.Parse(Console.ReadLine());
Console.WriteLine("\n" + solution.IsPalindrome(num));
}
}
}