Clean java


  • 0
    C
    public class Solution {
        int count;
        
        public int countSubstrings(String s) {
            count = 0;
            for (int i = 0; i < s.length(); i++){
                count ++;
                increOne(s, i);
                increTwo(s, i);
            }
            return count;
        }
        
        public void increOne(String s, int start){
            
            int right = start + 1;
            int left = start - 1;
            
            while (left >= 0 && right < s.length() && s.charAt(right) == s.charAt(left)){
                count ++;
                right ++;
                left --;
            }
        
        }
        
        public void increTwo(String s, int start){
            
            int right = start + 1;
            int left = start;
            
            while (left >= 0 && right < s.length() && s.charAt(right) == s.charAt(left)){
                count ++;
                right ++;
                left --;
            }
            
        }
        
        
    }
    
    
    

Log in to reply
 

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