Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit44b8019

Browse files
authored
Create 125_Valid_Palindrome.swift
1 parent51bcb14 commit44b8019

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎swift/125_Valid_Palindrome.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Question Link: https://leetcode.com/problems/valid-palindrome/
3+
*/
4+
5+
classValidPalindrome{
6+
func isPalindrome(_ s:String)->Bool{
7+
varl=0,r= s.count-1
8+
letsChars=Array(s.lowercased())
9+
10+
while l< r{
11+
while !sChars[l].isAlphanumeric && l< r{
12+
l+=1
13+
}
14+
15+
while !sChars[r].isAlphanumeric && l< r{
16+
r-=1
17+
}
18+
19+
ifsChars[l]!=sChars[r]{
20+
returnfalse
21+
}else{
22+
l+=1
23+
r-=1
24+
}
25+
}
26+
returntrue
27+
}
28+
}
29+
30+
extensionCharacter{
31+
varisAlphanumeric:Bool{
32+
return isLetter || isNumber
33+
}
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp