Valid Palindrome | LeetCode 125 | C++, Java, Python

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

**** Best Books For Data Structures & Algorithms for Interviews:**********
*****************************************************************************

August LeetCoding Challenge | Problem 3 | Valid Palindrome | 3 August,
Facebook Coding Interview question,
google coding interview question,
leetcode,
Valid Palindrome,
Valid Palindrome c++,
Valid Palindrome Java,
Valid Palindrome python,
Valid Palindrome solution,
125. Valid Palindrome,

#CodingInterview #LeetCode #AugustCodingChallenge #Google #Amazon #Palindrome
Рекомендации по теме
Комментарии
Автор

Very nice solution.

The first line can be deleted, because for empty/single char string while (st < en) evaluates to false and true is returned by the last statement. However, the check improves runtime performance since the two int declarations and definitions are skipped.

peymanbr
Автор

I didn't get why we have to check for l<r even in the inner loop as it is already checked in the outer loop.

avinashpaul
Автор

Thank you so much sir . Completely Understood the problem.

shycoder
Автор

bro u explain the code lines very well...THNX a lot and please continue explaining complex code lines...Keep going, , we are supporting u ..

mandeep
Автор

class Solution {
public:
bool isPalindrome(string s) {
string str = "";
for(auto x : s)
if(isalnum(x))
{
x = ::tolower(x);
str += x;
}

string rStr = str;
std::reverse(rStr.begin(), rStr.end());

if(str == rStr)
return true;

return false;
}
};
C++ solution using std::reverse

antonios-m
Автор

Can someone help?
While loop ke andar waale while loops m st < en waali condition dobaara kyu likhte hainn

aisharawat
Автор

can any one tell why i am getting Expected answer as True and My answer for 1st test case as FALSE. though copying the same.

class Solution:
def isPalindrome(self, s: str) -> bool:
if len(s) <= 1:
return True
st = 0
en = len(s)-1
while st < en :
while st < en and not s[st].isalnum():
st += 1
while st < en and not s[en].isalnum():
en -= 1
if st < en and s[st].lower != s[en].lower():return False
st += 1
en -= 1
return True

travel_geek_banglore
Автор

sir please solve this problem also => 1411. Number of Ways to Paint N × 3 Grid

siddharthsingh
Автор

Nice way but the test case
"race a car" Fails

abdul
Автор

Please make a video on longest palindrome in a string

raviashwin