Skip to content

Commit

Permalink
updating README
Browse files Browse the repository at this point in the history
  • Loading branch information
flohei committed Oct 18, 2018
1 parent 5fe31ff commit 93a4d2d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Palindromes/README.markdown
Expand Up @@ -26,7 +26,7 @@ Here is a recursive implementation of this in Swift:
```swift
func isPalindrome(_ str: String) -> Bool {
let strippedString = str.replacingOccurrences(of: "\\W", with: "", options: .regularExpression, range: nil)
let length = strippedString.characters.count
let length = strippedString.count

if length > 1 {
return palindrome(strippedString.lowercased(), left: 0, right: length - 1)
Expand Down

1 comment on commit 93a4d2d

@konrri2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

question about time complexity:

str.index(str.startIndex, offsetBy: i) has time complexity O(n), so the whole function has O(n^2)

Wouldn't it be better if I use

        str.formIndex(after: &iLeft)
        str.formIndex(before: &iRight)

???

Regards,
Konrad

Please sign in to comment.