Skip to content

Commit 1b3adb8

Browse files
authored
Create Valid Palindrome
1 parent d873d96 commit 1b3adb8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Valid Palindrome

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public boolean isPalindrome(String s) {
3+
String line = "";
4+
String reverse = "";
5+
for(int i = 0; i<s.length(); i++){
6+
if((s.charAt(i) >= 'A' && s.charAt(i)<='Z') || (s.charAt(i) >= 'a' && s.charAt(i)<='z') ||(s.charAt(i)>='0' && s.charAt(i)<='9')){
7+
line += s.charAt(i)+"";
8+
}
9+
}
10+
line = line.toLowerCase();
11+
//System.out.println(line);
12+
return reverse(line).equals(line);
13+
}
14+
15+
public static String reverse(String a){
16+
String result = "";
17+
for(int i = a.length()-1; i>=0; i--){
18+
result += a.charAt(i);
19+
}
20+
21+
return result;
22+
}
23+
24+
25+
}

0 commit comments

Comments
 (0)