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

Update 0125-valid-palindrome.js#2535

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

Merged
aakhtar3 merged 2 commits intoneetcode-gh:mainfromacidbluebriggs:patch-1
Jun 30, 2023
Merged

Update 0125-valid-palindrome.js#2535

aakhtar3 merged 2 commits intoneetcode-gh:mainfromacidbluebriggs:patch-1
Jun 30, 2023

Conversation

@acidbluebriggs
Copy link
Contributor

@acidbluebriggsacidbluebriggs commentedMay 31, 2023
edited
Loading

Added a new 2 pointer implementation that doesn't use RegEx (only primitives), and doesn't create new strings.

Added a new 2 pointer implementation that doesn't use RegEx (only primitives), and no copying of strings.
Copy link
Collaborator

@aakhtar3aakhtar3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Check suggestions

varisPalindrome=function(s){
constisAlpha=c=>(c.toLowerCase()>='a'&&c.toLowerCase()<='z')||c>='0'&&c<='9'

leti=0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggestion: use a more readable variable name like 'left' and 'right'

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I did some refactoring per your suggestion

letj=s.length-1;

while(i<j){
if(!isAlpha(s.charAt(i))){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggestion: avoid else

Suggested change
if(!isAlpha(s.charAt(i))){
if(isInvalid)returnfalse;
if(canMoveLeft){left++;continue;}
if(canMoveRight){right--;continue;}
left++;
right--;

Copy link
ContributorAuthor

@acidbluebriggsacidbluebriggsJun 6, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please check current changes. I have introduced some variables for clarity.

* Clarified some variable and internal function names* Removed if/else conditions* Introduced new variables to increase clarity
@aakhtar3aakhtar3 merged commitd11684b intoneetcode-gh:mainJun 30, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@aakhtar3aakhtar3aakhtar3 left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@acidbluebriggs@aakhtar3

[8]ページ先頭

©2009-2025 Movatter.jp