leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | d73581d247cf1608adebfb2b20eb570f5ab66892 |
parent | 472a1ca2bbf5e26c5a2db5e5bc71135e7280fc94 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Sat, 25 Feb 2023 14:21:31 +0100 |
Random Problem
Diffstat:A | Problems/0009.cpp | | | +++++++++ |
M | README.md | | | + |
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/Problems/0009.cpp b/Problems/0009.cpp
@@ -0,0 +1,9 @@
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0 || (x != 0 && x % 10 == 0)) return false;
int sum = 0;
do { sum = sum * 10 + x % 10; } while ((x /= 10) > sum);
return (x == sum) || (x == sum / 10);
}
};
diff --git a/README.md b/README.md
@@ -462,4 +462,5 @@ for solving problems.
| 2477 | Medium | [Minimum Fuel Cost to Report to the Capital](Problems/2477.cpp) |
| 2492 | Medium | [Minimum Score of a Path Between Two Cities](Problems/2492.cpp) |
| 2497 | Medium | [Maximum Star Sum of a Graph](Problems/2497.cpp) |
| 0009 | Easy | [Palindrome Number](Problems/0009.cpp) |