Skip to content

Commit 13c0e4c

Browse files
committed
added palindrome checker using stack
1 parent 4aa01da commit 13c0e4c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/main/java/com/thealgorithms/stacks/PalindromeWithStack.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* Reference: https://www.geeksforgeeks.org/check-whether-the-given-string-is-palindrome-using-stack/
1111
*/
12-
public final class PalindromeWithStack {
12+
public class PalindromeWithStack {
1313
private LinkedList<Character> stack;
1414

1515
/**
@@ -28,14 +28,14 @@ public PalindromeWithStack() {
2828
*
2929
* @param string The string to check if it is palindrome or not.
3030
*/
31-
public final boolean checkPalindrome(final String string) {
31+
public boolean checkPalindrome(String string) {
3232
// Create a StringBuilder to build the string from left to right
3333
StringBuilder stringBuilder = new StringBuilder(string.length());
3434
// Convert all characters to lowercase
3535
String lowercase = string.toLowerCase();
3636

3737
// Iterate through the string
38-
for(int i = 0; i < lowercase.length(); ++i) {
38+
for (int i = 0; i < lowercase.length(); ++i) {
3939
char c = lowercase.charAt(i);
4040
if (c >= 'a' && c <= 'z') {
4141
// Build the string from L->R
@@ -48,7 +48,7 @@ public final boolean checkPalindrome(final String string) {
4848
// The stack contains the reverse order of the string
4949
StringBuilder reverseString = new StringBuilder(stack.size());
5050
// Until the stack is not empty
51-
while (!stack.isEmpty()){
51+
while (!stack.isEmpty()) {
5252
// Build the string from R->L
5353
reverseString.append(stack.pop());
5454
}

0 commit comments

Comments
 (0)