private boolean isPalindrome(String str) {

    if (str.isEmpty()) {
      return true;
    }

    int head = 0;
    int tail = str.length() - 1;

    while (head < tail) {
      if (str.charAt(head) == str.charAt(tail)) {
        head++;
        tail--;
      } else {
        return false;
      }
    }

    return true;
  }