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

Valid Palindrome#2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ifenil wants to merge2 commits intoNirmalSilwal:master
base:master
Choose a base branch
Loading
fromifenil:master
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletionsLeetcode/Leetcode_August_Challenge/Valid_Palindrome.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
package Leetcode_August_Challenge;

public class Valid_Palindrome {

public boolean isPalindrome(String s) {
// check string if it's null no need to go further direct return false

if(s==null){
return false;
}

// if string contain some char as uppercase or lowercase
// this will convert whole string to lowercase
s = s.toLowerCase();

// pointed i to intially at 0
// and j to end of the string (last character)
int i=0;
int j=s.length()-1;


while(i<j){
//if i<j and string char contain a-z and 0-9 loop -> true

while(i<j && !((s.charAt(i)>='a' && s.charAt(i)<='z')
|| (s.charAt(i)>='0'&&s.charAt(i)<='9'))){
i++;
}

while(i<j && !((s.charAt(j)>='a' && s.charAt(j)<='z')
|| (s.charAt(j)>='0'&&s.charAt(j)<='9'))){
j--;
}
// if one of string char not match i to j
// it will return false
if(s.charAt(i) != s.charAt(j)){
return false;
}

i++;
j--;
}
// else return true
return true;

}
}

[8]ページ先頭

©2009-2025 Movatter.jp