¡GoConqr estrena diseño! Cuéntanos qué te parece.

Fichas

Palindromic Substrings - Leetcode

Suhas S Inglés 1 ficha

Fichas del conjunto (1)

  1. 1Given a string, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters. Input: "abc" Output: 3 Explanation: Three palindromic strings: "a", "b", "c".class Solution {
    int count = 0;
    public int countSubstrings(String s) {
    for(int i = 0; i < s.length(); i++){
    extendPalindrome(s,i,i);
    extendPalindrome(s,i,i+1);
    }
    return count;
    }
    private void extendPalindrome(String s, int left, int right){
    while(left >=0 && right < s.length() && s.charAt(left) == s.charAt(right)){
    count++;
    left--;
    right++;
    }
    }
    }

Información

Descripción
Fichas sobre Palindromic Substrings - Leetcode, creado por Suhas S el 24/03/2018.
Creado por
Suhas S
Visitas
2
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?