CodeSignal-checkPalindrome

Sean·2022년 1월 17일

CodeSignal

목록 보기
3/5

Given the string, check if it is a palindrome.

Example

For inputString = "aabaa", the output should be
solution(inputString) = true;
For inputString = "abac", the output should be
solution(inputString) = false;
For inputString = "a", the output should be
solution(inputString) = true.
Input/Output

[execution time limit] 3 seconds (java)

[input] string inputString

A non-empty string consisting of lowercase characters.

Guaranteed constraints:
1 ≤ inputString.length ≤ 105.

[output] boolean

true if inputString is a palindrome, false otherwise.

boolean solution(String inputString) {
	String comp = new StringBuilder(inputString).reverse().toString();
    
    	if(inputString.equals(comp))
    	{
    		return true;
    	}
    	else
    	{
    		return false;
    	}
}

0개의 댓글