LeetCode – 125. Valid Palindrome

題目連結: https://leetcode.com/problems/valid-palindrome/

Time complexity: O(n)

    func isPalindrome(_ s: String) -> Bool {
        var arr = Array(s)
        var i = 0
        var j = arr.count - 1
        while i < j {
        	if !arr[i].isLetter && !arr[i].isNumber {
        		i += 1
        	} else if !arr[j].isLetter && !arr[j].isNumber { 
        		j -= 1
        	} else {
        		if arr[i].lowercased() != arr[j].lowercased() {
        			return false
        		} else {
        			i += 1
        			j -= 1
        		}
        	}
        }
        return true
    }