GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

Palindromic Substrings - Leetcode

Suhas S Englisch 1 Karte

Karten in diesem Stapel (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++;
    }
    }
    }

Informationen

Beschreibung
Karteikarten am Palindromic Substrings - Leetcode, erstellt von Suhas S am 24/03/2018.
Erstellt von
Suhas S
Aufrufe
2
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck