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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started