Simple Java Solution


  • 0
    V
    class Solution {
        public boolean validPalindrome(String s) 
        {
        		char []a = s.toCharArray();
        		
        		int i = 0;
        		
        		int j = a.length -1;
        		
        		
        		while (i<j)
        		{
        			if (a[i] == a[j])
        			{
        				i++;
        				j--;
        			}
        			else
        			{
        				return (isValidPalindrome(s,i,j-1) || isValidPalindrome(s,i+1,j));
        			}
        		}
        		
        		return true;
        }
        
        public static boolean isValidPalindrome(String s,int left , int right) 
        {
        		char []a = s.toCharArray();
        		   		
        		while (left<right)
        		{
        			if (a[left] == a[right])
        			{
        				left ++;
        				right --;
        			}
        			else
        			{
        				return false;
        			}
        		}
        		
        		return true;
        }
    }
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.