Leetcode | 9. Palindrome Number | Easy | Java Solution

preview_player
Показать описание


#leetcode #leetcodesolution #java
Рекомендации по теме
Комментарии
Автор

Hey it's integer and instead of creating object we can reverse and verify
private static boolean isPalidrom(int num){
if(num<0){
return false;
}
int temp = num;
int sum = 0;
while(num>0){
int rem = num%10;
sum = sum*10+rem;
num = num/10;
}
return temp==sum;
}

virendrastock
Автор

We can use 2 pointer idea
One pointer from forwards
Other pointer from backward

Easily compute the answer bro

myosith
Автор

see this easy way

class Solution {
public boolean isPalindrome(int x) {
String num = String.valueof(x);
String reversed = new
return num.equals(reversed);
}
}

YosuwaK
Автор

int x = 32323;
String y = String.valueOf(x);
char c[] = y.toCharArray();

char temp = 0;

for (int i = 0; i < c.length / 2; i++) {

temp = c[i];
c[i] = c[c.length - i - 1];
c[c.length - i - 1] = temp;
}

if (String.valueOf(c).equals(y)) {

} else {

}

gauravvarma
Автор

But, can you solve the question without converting to String?

ashimroy
visit shbcf.ru