static bool IsPalindrome(int n)
{
return n.ToString() == Reverse(n.ToString());
}
static string Reverse(string str)
{
return new string(str.ToCharArray().Reverse().ToArray());
}
Copy
public class Solution {
public bool IsPalindrome(int x) {
string first = x.ToString(); //turn to string (easy to reverse)
char[] charArr = first.ToCharArray(); //the original target
char[] reverseArr = first.ToCharArray();
Array.Reverse(reverseArr );
return charArr.SequenceEqual(reverseArr); //compare two array
}
}
Code Example |
---|
Csharp :: laravel get current url |
Csharp :: git set origin |
Html :: html rupee symbol |
Html :: html yen symbol |
Html :: html input integer and positive |
Html :: email regex html pattern |
Html :: espacio html |
Html :: html anchor tag open in new tab |
Html :: regex find html comment |
Html :: free video url for testing |
Html :: html input box no border |
Html :: divi font awesome |
Html :: remove html tags from string python |
Html :: html center image vertically bootstrap |
Html :: regex remove html comment |
Html :: add favicon html |
Html :: how to link new tab in html button |
Html :: laravel blade remove all html tags |
Html :: iframe adjust pdf zoom |
Html :: bootstrap side by side columns |
Html :: mobile prevent zoom |
Html :: html estrutura |
Html :: font awesome src |
Html :: select in vee validate |
Html :: align image center of webpage |
Html :: dont show suggestions in input hs |
Html :: footer ionic |
Html :: calendar input |
Html :: mailto html |
Html :: bootstrap display none |