Posted by admin June 26th 2018 at 20:06

John and Brus are studying string theory at the university.
Brus likes palindromes very much.
A palindrome is a word that the same forword and backword.
John would like to surprise Brus by taking a String s, and appending 0 or more characters to the end of s to obtain a palindrome.
He wants that palindrome to be as short as possible.
Return the shortest possible length of a plaindrome that John can generate.


var str : String = "qwerty"

var charArr : [Character] = Array(str.characters)

var count : Int = charArr.count

var bool : Bool = true

for i in (0...count-1).reversed() {


    if(bool){


        for j in 0...count-1 {


            if i>j {


                if charArr[i] != charArr[j] {


                    count += 1


                }else{


                    bool = false


                    break

                }


            }else if i==j{


                bool = false


            }

        }


    }else{


        break


    }

}

print(count)