From 60ff3aae300ae46210252609b5540d00adb20226 Mon Sep 17 00:00:00 2001 From: Sahil ahmed <78746946+sahilahmed24@users.noreply.github.com> Date: Fri, 1 Oct 2021 18:40:22 +0530 Subject: [PATCH] Resolved Issue #12 Palindrome Number I have completed the Palindrome Number solution in java hope it passes all the criteria of being merged . please also mark the label of hacktoberfest-accepted . Also thank you for your support --- Java/palindrome_num.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Java/palindrome_num.java diff --git a/Java/palindrome_num.java b/Java/palindrome_num.java new file mode 100644 index 0000000..6204d2e --- /dev/null +++ b/Java/palindrome_num.java @@ -0,0 +1,28 @@ +/*Link Of Question : https://leetcode.com/problems/palindrome-number/ +#12. Palindrome Number +Given an integer x, return true if x is palindrome integer +*/ +//Solution : + +public class Solution { + public boolean isPalindrome(int x) { + int sum = 0,target = x; + while (x > 0) { + int temp = x % 10; + x /= 10; + sum = sum * 10 + temp; + } + return sum == target; + } +} + +/* +Sample Input 1 : x=121 +Sample output 1 : true + +Sample input 2 : x= -121 +Sample output 1 : false +/* + + + \ No newline at end of file