Leetcode 9. Palindrome Number

preview_player
Показать описание
Palindrome Number Leetcode 9,Palindrome Number Leetcode, Leetcode, Palindrome Number, Leetcode Solution, Palindrome Number Leetcode 9 solution, Palindrome Number Leetcode 9 solution java, Palindrome Number solution, Palindrome Number Solution Java,

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

Java Solution code:


class Solution {
public boolean isPalindrome(int x) {

String xAsString= String.valueOf(x);

int begin_ptr =0;
int end_ptr=xAsString.length()-1;

while(begin_ptr<=end_ptr)
{

{
begin_ptr++;
end_ptr --;
}else
return false;

}

return true;


}
}

pratikshabakrola
Автор

Thanks for the video, it's enough to write begin_ptr < end_ptr since the condition will succeed if it's the same index.

DrorGuy
Автор

Hey, one suggestion if you can also explain the time complexity and space complexity that will be helpful.

SmplifiedCoding
Автор

Another way it can be done is to reverse the input number and then compare the inverted number with the original one. If they're equal then the original number is palindrome. The time complexity is the same as your solution O(n).

BogdanHladiuc
Автор

Python Solution Code:

class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0: return False

div = 1

while x >= 10 * div:
div = div * 10

while x > 0:
right = x % 10
left = x // div

if right != left: return False

x = (x % div) // 10
div = div / 100
return True

daileecode
Автор

can you add more solutions like blind 75 list ???

RockstarHectocorn