This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Program { | |
public static boolean isPalindrome(String str) { | |
// handle corner cases | |
if (str == null || str.length() < 2) { | |
return true; | |
} | |
int begin = 0; int end = str.length() - 1; | |
while (begin < end) { | |
if (str.charAt(begin) != str.charAt(end)) { | |
return false; | |
} | |
begin++; | |
end--; | |
} | |
return true; | |
} | |
} |
No comments:
Post a Comment