From e4066c7c797e2ac4ef0484c575666098e96f9de5 Mon Sep 17 00:00:00 2001 From: yubin <59639035+gogumaC@users.noreply.github.com> Date: Thu, 2 Jan 2025 23:16:53 +0900 Subject: [PATCH] Time: 3 ms (40.21%), Space: 8.2 MB (42.98%) - LeetHub --- .../0009-palindrome-number.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 0009-palindrome-number/0009-palindrome-number.c diff --git a/0009-palindrome-number/0009-palindrome-number.c b/0009-palindrome-number/0009-palindrome-number.c new file mode 100644 index 0000000..6b85f4b --- /dev/null +++ b/0009-palindrome-number/0009-palindrome-number.c @@ -0,0 +1,29 @@ +bool isPalindrome(int x) { + + int len = 0; + int xx = x; + do + { + xx/=10; + len++; + }while(xx); + + if(x<0) + { + len++; + } + + char str[len+1]; + sprintf(str,"%d",x); + + for(int i=0; i<=len/2; i++) + { + if(str[i]!=str[len-i-1]) + { + return false; + } + } + + return true; + +} \ No newline at end of file