Skip to content

Commit 3cccec0

Browse files
author
codehouseindia
authored
Merge pull request codehouseindia#136 from ankit10126/patch-1
Create string palindrome
2 parents 686ca40 + 81af8e4 commit 3cccec0

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

string palindrome

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}

0 commit comments

Comments
 (0)