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

Commit6f1e35e

Browse files
committed
125
1 parentbd52434 commit6f1e35e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

‎ruby/125-Valid-Palindrome.rb‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
defis_palindrome(s)
2+
str=s.downcase.chars.select{ |char|/[a-zA-Z0-9]/.match?(char)}.join
3+
idx_start=0
4+
idx_end=str.length -1
5+
whileidx_start <idx_end
6+
returnfalseifstr[idx_start] !=str[idx_end]
7+
8+
idx_start +=1
9+
idx_end -=1
10+
end
11+
true
12+
end
13+
14+
defis_palindrome(s)
15+
idx_start=0
16+
idx_end=s.length -1
17+
whileidx_start <idx_end
18+
if !/[a-zA-Z0-9]/.match?(s[idx_start])
19+
idx_start +=1
20+
elsif !/[a-zA-Z0-9]/.match?(s[idx_end])
21+
idx_end -=1
22+
else
23+
returnfalseifs[idx_start].downcase !=s[idx_end].downcase
24+
25+
idx_start +=1
26+
idx_end -=1
27+
end
28+
end
29+
true
30+
end
31+
32+
defis_palindrome(s)
33+
str=s.downcase.chars.select{ |char|/[a-zA-Z0-9]/.match?(char)}
34+
str ==str.reverse
35+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp