-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a4ad40
commit 355f9d4
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |