Determines whether an integer is a return value. The Return Value refers to the integer that reads data in the forward (from left to right) and backward (from right to left.
Example 1:
Input: 121 output: True
Example 2:
Input:-121 output: false explanation: read from left to right, which is-121. Read from right to left, which is 121 -. Therefore, it is not a return number.
Example 3:
Input: 10 output: false explanation: read from right to left, 01. Therefore, it is not a return number.
Answer:
class Solution { public boolean isPalindrome(int x) { boolean flag=false; String x1=""+x; char[] x2=x1.toCharArray(); char[] x3=x1.toCharArray(); for (int i = 0; i < x2.length/2; i++) { char temp = x2[i]; x2[i]=x2[x2.length-1-i]; x2[x2.length-1-i]=temp; } for(int i=0;i<x2.length;i++){ if (x2[i]==x3[i]) { flag=true; }else { flag=false; break; } } return flag; }}
Submission result:
Leetcode record-number of replies