Question: //Can you explain to me why exactly is my code not working? //JAVA leetcode question //Question: Given a string s, return true if the s

//Can you explain to me why exactly is my code not working?

//JAVA leetcode question

//Question: Given a string s, return true if the s can be palindrome after deleting at most one character from it.

//My code :

class Solution {

public boolean validPalindrome(String s) {

int removeCounter=0,a=0,b=1;

String ns="";

for(int i=0;i

if(Character.isDigit(s.charAt(i))||Character.isLetter(s.charAt(i)))

ns+=s.charAt(i);

}

ns=ns.toLowerCase();

int l = ns.length();

for(int i=0;i

if(ns.charAt(i+a)!=ns.charAt(l-b-i)){

removeCounter++;

if(removeCounter<1 && l-b-i>1 && i+a

if(ns.charAt(i+a)==ns.charAt(l-(b+1)-i))

b++;

else if(ns.charAt(i+(a+1))==ns.charAt(l-b-i))

a++;

else

return false;

}

}

if (removeCounter>1)

return false;

return true;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!