9
9
*
10
10
* Reference: https://www.geeksforgeeks.org/check-whether-the-given-string-is-palindrome-using-stack/
11
11
*/
12
- public final class PalindromeWithStack {
12
+ public class PalindromeWithStack {
13
13
private LinkedList <Character > stack ;
14
14
15
15
/**
@@ -28,14 +28,14 @@ public PalindromeWithStack() {
28
28
*
29
29
* @param string The string to check if it is palindrome or not.
30
30
*/
31
- public final boolean checkPalindrome (final String string ) {
31
+ public boolean checkPalindrome (String string ) {
32
32
// Create a StringBuilder to build the string from left to right
33
33
StringBuilder stringBuilder = new StringBuilder (string .length ());
34
34
// Convert all characters to lowercase
35
35
String lowercase = string .toLowerCase ();
36
36
37
37
// Iterate through the string
38
- for (int i = 0 ; i < lowercase .length (); ++i ) {
38
+ for (int i = 0 ; i < lowercase .length (); ++i ) {
39
39
char c = lowercase .charAt (i );
40
40
if (c >= 'a' && c <= 'z' ) {
41
41
// Build the string from L->R
@@ -48,7 +48,7 @@ public final boolean checkPalindrome(final String string) {
48
48
// The stack contains the reverse order of the string
49
49
StringBuilder reverseString = new StringBuilder (stack .size ());
50
50
// Until the stack is not empty
51
- while (!stack .isEmpty ()){
51
+ while (!stack .isEmpty ()) {
52
52
// Build the string from R->L
53
53
reverseString .append (stack .pop ());
54
54
}
0 commit comments