Check if string is palindrome in objective c

前端 未结 10 2213
执念已碎
执念已碎 2021-01-07 02:15

I\'m trying to check if a string is palindrome or not using objective c. I\'m new to programming without any experience in other programming languages so bear with me please

10条回答
  •  别那么骄傲
    2021-01-07 02:50

    var str: NSString = "123321"
    var length = str.length
    var isPalindrome = true
    
    for index in 0...length/2{
        if(str.characterAtIndex(index) != str.characterAtIndex(length-1 - index)){
            print("\(index )not palindrome")
            isPalindrome = false
            break
        }
    }
    
    print("is palindrome: \(isPalindrome)")
    

提交回复
热议问题