mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-18 00:57:17 +00:00
Add solution to 'a lot' of problems
This commit is contained in:
20
Easy/valid-palindrome/solution.java
Normal file
20
Easy/valid-palindrome/solution.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user