diff --git a/solution/0000-0099/0009.Palindrome Number/README.md b/solution/0000-0099/0009.Palindrome Number/README.md index c0e23b1f63b38..ee1c738dee14d 100644 --- a/solution/0000-0099/0009.Palindrome Number/README.md +++ b/solution/0000-0099/0009.Palindrome Number/README.md @@ -210,6 +210,27 @@ var isPalindrome = function (x) { }; ``` +#### C# + +```cs +public class Solution +{ + public bool IsPalindrome(int x) + { + if (x < 0 || (x > 0 && x % 10 == 0)) + { + return false; + } + int y = 0; + for (; y < x; x /= 10) + { + y = y * 10 + x % 10; + } + return x == y || x == y / 10; + } +} +``` + #### PHP ```php diff --git a/solution/0000-0099/0009.Palindrome Number/README_EN.md b/solution/0000-0099/0009.Palindrome Number/README_EN.md index 0392466009818..5616eee00755d 100644 --- a/solution/0000-0099/0009.Palindrome Number/README_EN.md +++ b/solution/0000-0099/0009.Palindrome Number/README_EN.md @@ -202,6 +202,27 @@ var isPalindrome = function (x) { }; ``` +#### C# + +```cs +public class Solution +{ + public bool IsPalindrome(int x) + { + if (x < 0 || (x > 0 && x % 10 == 0)) + { + return false; + } + int y = 0; + for (; y < x; x /= 10) + { + y = y * 10 + x % 10; + } + return x == y || x == y / 10; + } +} +``` + #### PHP ```php diff --git a/solution/0000-0099/0009.Palindrome Number/Solution.cs b/solution/0000-0099/0009.Palindrome Number/Solution.cs new file mode 100644 index 0000000000000..b58946514c161 --- /dev/null +++ b/solution/0000-0099/0009.Palindrome Number/Solution.cs @@ -0,0 +1,16 @@ +public class Solution +{ + public bool IsPalindrome(int x) + { + if (x < 0 || (x > 0 && x % 10 == 0)) + { + return false; + } + int y = 0; + for (; y < x; x /= 10) + { + y = y * 10 + x % 10; + } + return x == y || x == y / 10; + } +} \ No newline at end of file