Skip to main content
added 90 characters in body
Source Link
vnp
  • 58.7k
  • 4
  • 55
  • 144
  • A special case length < 3 seems like a bug. A string aa is a palindrome, and one could successfully argue that a single-letter string is also a palindrome.

  • A boolean isPalindrome is redundant, and forces the code to test the effectively same condition twice. An early return is perfectly fine here.

  • A traditional idiomatic (and arguably more performant) way to iterate forward is *first++. Similarly, an idiom for iterating backwards is *--last (that also avoids subtracting 1 beforehand):

          last = possiblePalindrome.end();
          while (first < last) {
              if (*first++ != *--last) {
                  return false;
              }
          }
          return true;
    
  • The naming is very inconsistent. I don't see the reason to spell palindrome in 3 different ways. A capitalization in iSPalendrome is also strange.

  • A special case length < 3 seems like a bug. A string aa is a palindrome, and one could successfully argue that a single-letter string is also a palindrome.

  • A boolean isPalindrome is redundant, and forces the code to test the effectively same condition twice. An early return is perfectly fine here.

  • A traditional idiomatic (and arguably more performant) way to iterate forward is *first++. Similarly, an idiom for iterating backwards is *--last:

          while (first < last) {
              if (*first++ != *--last) {
                  return false;
              }
          }
          return true;
    
  • The naming is very inconsistent. I don't see the reason to spell palindrome in 3 different ways. A capitalization in iSPalendrome is also strange.

  • A special case length < 3 seems like a bug. A string aa is a palindrome, and one could successfully argue that a single-letter string is also a palindrome.

  • A boolean isPalindrome is redundant, and forces the code to test the effectively same condition twice. An early return is perfectly fine here.

  • A traditional idiomatic (and arguably more performant) way to iterate forward is *first++. Similarly, an idiom for iterating backwards is *--last (that also avoids subtracting 1 beforehand):

          last = possiblePalindrome.end();
          while (first < last) {
              if (*first++ != *--last) {
                  return false;
              }
          }
          return true;
    
  • The naming is very inconsistent. I don't see the reason to spell palindrome in 3 different ways. A capitalization in iSPalendrome is also strange.

Source Link
vnp
  • 58.7k
  • 4
  • 55
  • 144

  • A special case length < 3 seems like a bug. A string aa is a palindrome, and one could successfully argue that a single-letter string is also a palindrome.

  • A boolean isPalindrome is redundant, and forces the code to test the effectively same condition twice. An early return is perfectly fine here.

  • A traditional idiomatic (and arguably more performant) way to iterate forward is *first++. Similarly, an idiom for iterating backwards is *--last:

          while (first < last) {
              if (*first++ != *--last) {
                  return false;
              }
          }
          return true;
    
  • The naming is very inconsistent. I don't see the reason to spell palindrome in 3 different ways. A capitalization in iSPalendrome is also strange.