We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0c64864 commit 47e6f66Copy full SHA for 47e6f66
Easy/125.Valid Palindrome.playground/Contents.swift
@@ -27,6 +27,28 @@
27
*/
28
class Solution {
29
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 {
52
var newStr = ""
53
for c in s {
54
if ("a"..."z").contains(c.lowercased()) {
0 commit comments