From 4a81d5d4b65e8153f93bf0845db4b5b0be3e27a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Velimir=20=C4=90urkovi=C4=87?= Date: Tue, 4 Feb 2025 02:38:50 +0100 Subject: [PATCH] feat: add csharp solution to lc problem: No.0009 --- .../0009.Palindrome Number/README.md | 21 +++++++++++++++++++ .../0009.Palindrome Number/README_EN.md | 21 +++++++++++++++++++ .../0009.Palindrome Number/Solution.cs | 16 ++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 solution/0000-0099/0009.Palindrome Number/Solution.cs 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