Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions