My solution with iteration


  • 0
    S

    public int countSubstrings(String s) {
    int length = s.length();
    int count = 0;

            for(int k=0;k<s.length();k++){
                               
                for(int j=0;j<s.length()-k;j++){
                	int temp=0;
                 String newString= s.substring(k,length-j);
                  System.out.println(newString);
                    int l_newS= newString.length();
                    for(int i=0;i<l_newS/2;i++){
                        if(newString.charAt(i)!=newString.charAt(l_newS-i-1))
                         {
                            temp++;
                             break;
                        }
                    }
                    	if(temp==0) {
                    		count++;
                    
                    	}
            }
            }
    

    return count;
    }


Log in to reply
 

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