title: palindromes count swift optimization
body: <p>Hey i have a question about optimization palindromes count algorithm </p>
  
  <blockquote>
    <p>Task: Find count of palindromes in string.</p>
  </blockquote>
  
  <p>in my func i use "in the forehead" method its like O(n^2)
  can you guys help make it in O(n) or O(nlogn)</p>
  
  <pre><code>func isPalindrome(string: String) -&gt; Bool {
      let str = (string.lowercased())
      let strWithoutSpace = str.components(separatedBy: .whitespaces).joined(separator: "")
      let strArray = Array(strWithoutSpace.characters)
      var i = 0
      var j = strArray.count-1
      while i &lt;= j {
          if strArray[i] != strArray[j] { return false }
          i+=1
          j-=1
      }
      return true
  }
  func palindromsInString(string: String) -&gt; Int {
      var arrayOfChars = Array(string.characters)
      var count = 0
      for i in 0..&lt;arrayOfChars.count-1 {
          for x in i+1..&lt;arrayOfChars.count {
              if isPalindrome(string: String(arrayOfChars[i...x])) {
                  count+=1
              }
          }
      }
      return count
  }
  </code></pre>
  
  <p>and yes in my instance one letter can't be a palindrome</p>