forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValid Palindrome.java
37 lines (35 loc) · 889 Bytes
/
Valid Palindrome.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Runtime: 313 ms (Top 34.84%) | Memory: 43.9 MB (Top 52.81%)
class Solution {
public boolean isPalindrome(String s) {
if(s.length()==1 || s.length()==0)
{
return true;
}
s=s.trim().toLowerCase();
//s=s.toLowerCase();
String a="";
boolean bool=false;
for(int i=0;i<s.length();i++)
{
if((s.charAt(i)>='a' && s.charAt(i)<='z') || (s.charAt(i)>='0' && s.charAt(i)<='9'))
{
a=a+s.charAt(i);
}
}
if(a.length()==1 || a.length()==0)
{
return true;
}
for(int i=0;i<a.length()/2;i++)
{
if(a.charAt(i)==a.charAt(a.length()-i-1))
{
bool=true;
}
else{
return false;
}
}
return bool;
}
}