Skip to content

Commit f68aba0

Browse files
Update Palindrome.java
Using while loop from start to end
1 parent a163816 commit f68aba0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/java/com/thealgorithms/strings/Palindrome.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,22 @@ public static boolean isPalindromeTwoPointer(String s) {
5656
return true;
5757
}
5858
}
59+
60+
/**
61+
*check if string is palindrome or not
62+
*
63+
* @param s a string to check
64+
* @return {@code true} if given string is palindrome, otherwise
65+
* {@code false}
66+
*/
67+
public static boolean isPalindromeTwoPointerwhileloop(String s){
68+
char[] charArray = word.to char Array();
69+
int start=0; int end= s.length-1;
70+
while(start<end){
71+
if (char Array[start]!= char Array[end]){
72+
return false;
73+
}
74+
start++; end--;
75+
}
76+
return true;
77+
}

0 commit comments

Comments
 (0)