Skip to content

Commit

Permalink
Create Palindrome sentence
Browse files Browse the repository at this point in the history
  • Loading branch information
dishathakurata authored Dec 6, 2024
1 parent 0a4ad40 commit 355f9d4
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Palindrome sentence
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//Palindrome sentence

import java.io.*;
import java.util.*;

class GFG {
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());

while(t > 0) {
String s = sc.nextLine();
Solution ob = new Solution();

if(ob.sentencePalindrome(s)) {
System.out.println("true");
}
else {
System.out.println("false");
}

t--;
}
}
}

class Solution {
public boolean sentencePalindrome(String s) {

int i = 0, j = s.length() - 1;

while(i < j) {
if(!Character.isLetterOrDigit(s.charAt(i))) {
i++;
}
else if(!Character.isLetterOrDigit(s.charAt(j))) {
j--;
}
else if(Character.toLowerCase(s.charAt(i)) == Character.toLowerCase(s.charAt(j))) {
i++;
j--;
}
else {
return false;
}
}

return true;
}
}

0 comments on commit 355f9d4

Please sign in to comment.