diff --git a/Palindrome sentence b/Palindrome sentence new file mode 100644 index 0000000..8bcdbf2 --- /dev/null +++ b/Palindrome sentence @@ -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; + } +}