Skip to content

Instantly share code, notes, and snippets.

@eduzol
Created January 9, 2018 10:00
Show Gist options
  • Save eduzol/f823b1c7b9cd5473603b484da3262362 to your computer and use it in GitHub Desktop.
Save eduzol/f823b1c7b9cd5473603b484da3262362 to your computer and use it in GitHub Desktop.
package com.experis.cisco.test.ExperisCisco;
public class ExperisTest
{
public static void main( String[] args )
{
String testStr = "race car";
ExperisTest test = new ExperisTest();
boolean isPalindrome = test.isPalindrome(testStr);
System.out.println(isPalindrome);
}
/**
* Identify if given string is a palindrome or not
*/
public boolean isPalindrome( String text ){
char[] arr = text.replaceAll("\\s+","").toCharArray();
int i = 0 ;
int k = arr.length -1;
while ( i != k ){
if ( arr[i] != arr[k] ){
return false;
}
i++;
k--;
}
return true;
}
}
function isPalindrome( text ){
let arr = text.replace(/\s/g,'').split("");
let i = 0 , k = arr.length-1;
while ( i != k ) {
if ( arr[i] !== arr[k] ){
return false;
}
i++;
k--;
}
return true;
}
console.log( isPalindrome("race car") );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment