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

Commita1862bb

Browse files
author
applewjg
committed
ValidPalindrome
Change-Id: Ie3f8f0727ad7512fa0f25c716b32994163533266
1 parent51bbc48 commita1862bb

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎ValidPalindrome.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Author: Andy, nkuwjg@gmail.com
3+
Date: Jan 17, 2015
4+
Problem: Valid Palindrome
5+
Difficulty: Easy
6+
Source: https://oj.leetcode.com/problems/valid-palindrome/
7+
Notes:
8+
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
9+
For example,
10+
"A man, a plan, a canal: Panama" is a palindrome.
11+
"race a car" is not a palindrome.
12+
Note:
13+
Have you consider that the string might be empty? This is a good question to ask during an interview.
14+
For the purpose of this problem, we define empty string as valid palindrome.
15+
16+
Solution: traverse from both side.
17+
*/
18+
publicclassSolution {
19+
publicbooleanisPalindrome(Strings) {
20+
s =s.toLowerCase().replaceAll("\\W","");
21+
System.out.println(s);
22+
for (inti =0,j =s.length() -1;i <j; ++i, --j) {
23+
if (s.charAt(i) !=s.charAt(j))
24+
returnfalse;
25+
}
26+
returntrue;
27+
}
28+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp