File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Easy/125.Valid Palindrome.playground Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 2727 */
2828class Solution {
2929 func isPalindrome( _ s: String ) -> Bool {
30+ var newStr = " "
31+ for c in s {
32+ if ( " a " ... " z " ) . contains ( c. lowercased ( ) ) {
33+ newStr. append ( c. lowercased ( ) )
34+ } else if ( " 0 " ... " 9 " ) . contains ( c) {
35+ newStr. append ( c)
36+ }
37+ }
38+ if newStr. isEmpty { return true }
39+ var left = newStr. startIndex
40+ var right = newStr. index ( before: newStr. endIndex)
41+ while left < right {
42+ if newStr [ left] != newStr [ right] {
43+ return false
44+ }
45+ left = newStr. index ( after: left)
46+ right = newStr. index ( before: right)
47+ }
48+ return true
49+ }
50+
51+ func isPalindrome2( _ s: String ) -> Bool {
3052 var newStr = " "
3153 for c in s {
3254 if ( " a " ... " z " ) . contains ( c. lowercased ( ) ) {
You can’t perform that action at this time.
0 commit comments