Add solution to 'a lot' of problems

This commit is contained in:
Arkaprabha Chakraborty
2022-08-01 13:28:06 +05:30
parent 20d44dfd5e
commit ccc376aea0
9 changed files with 180 additions and 1 deletions

View File

@@ -0,0 +1,20 @@
class Solution {
public boolean isPalindrome(String s) {
String t = "";
for (int i = 0; i < s.length(); ++i) {
int a = (int)s.charAt(i);
if (a >= (int)'A' && a <= (int)'Z') {
t += (char)(a - (int)'A' + (int)'a');
} else if (a >= (int)'a' && a <= (int)'z') {
t += (char)a;
} else if (a >= (int)'0' && a <= (int)'9') {
t += (char)a;
}
}
StringBuilder ob = new StringBuilder(t);
String r = ob.reverse().toString();
return t.compareTo(r) == 0;
}
}