Created
January 9, 2018 10:00
-
-
Save eduzol/f823b1c7b9cd5473603b484da3262362 to your computer and use it in GitHub Desktop.
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
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; | |
} | |
} |
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
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