Skip to content

Instantly share code, notes, and snippets.

@sbsatter
Created November 17, 2016 18:04
Show Gist options
  • Save sbsatter/7b4c2764f0d6f73a39e3eb803bf2d969 to your computer and use it in GitHub Desktop.
Save sbsatter/7b4c2764f0d6f73a39e3eb803bf2d969 to your computer and use it in GitHub Desktop.
Easiest and fastest palyndrome checker
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.next();
/* Enter your code here. Print output to STDOUT.
for(int i=0; i<s.length()/2; i++){
if(s.charAt(i) != s.charAt(s.length()-1-i)){
System.out.println("No");
System.exit(0);
}
}
System.out.println("Yes");*/
StringBuilder sb= new StringBuilder(s);
if( s.equals(sb.reverse().toString())){
System.out.println("Yes");
}else{
System.out.println("No");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment