File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #https://www.facebook.com/permalink.php?story_fbid=2439553476338458&id=100008514873543
2+ # subscibe by Code House
3+ // Java implementation of the approach
4+ public class GFG {
5+
6+ // Function that returns true if
7+ // str is a palindrome
8+ static boolean isPalindrome(String str)
9+ {
10+
11+ // Pointers pointing to the beginning
12+ // and the end of the string
13+ int i = 0, j = str.length() - 1;
14+
15+ // While there are characters toc compare
16+ while (i < j) {
17+
18+ // If there is a mismatch
19+ if (str.charAt(i) != str.charAt(j))
20+ return false;
21+
22+ // Increment first pointer and
23+ // decrement the other
24+ i++;
25+ j--;
26+ }
27+
28+ // Given string is a palindrome
29+ return true;
30+ }
31+
32+ // Driver code
33+ public static void main(String[] args)
34+ {
35+ String str = "geeks";
36+
37+ if (isPalindrome(str))
38+ System.out.print("Yes");
39+ else
40+ System.out.print("No");
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments