29 changes: 29 additions & 0 deletions 29 Substrings of Size Three with Distinct Characters/kata.java Original file line numberDiff line numberDiff line change @@ -0,0 +1,29 @@ class Solution { public int countGoodSubstrings(String s) { var k = 3; if (s.length() < k) { return...
Given 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. Example 1: Input: “abc” Output: 3 Explanation: Three palindromic strings:...
Given 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. Example 1: Input: "abc" Output: 3 Explanation: Three palindromic strings: ...
classSolution {public:intcountSubstrings(strings) {intres =0;for(inti =0; i < s.size(); i++) {for(intj =1; j <= s.size() - i; j++) {if(isPalindromic(s.substr(i, j))) res++; } }returnres; }boolisPalindromic(stringstr) {intlo =0, hi = str.size() -1;while(lo <hi...
1358 Number of Substrings Containing All Three Characters 包含所有三种字符的子字符串数目 Description: Given a string s consisting only of characters a, b and c. Return the number of substrings containing at least one occurrence of all these characters a, b and c. ...
A substring is a contiguous sequence of characters within the string. Example: Example 1: Input: s = "abc" Output: 3 Explanation: Three palindromic strings: "a", "b", "c". Example 2: Input: s = "aaa" Output: 6 Explanation: Six palindromic strings: "a", "a", "a", "aa", "...
Explanation: Three palindromic strings: "a", "b", "c". Example 2: Input: "aaa" Output: 6 Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa". Note: The input string length won't exceed 1000. 给了一个字符串,计算有多少个回文子字符串,不同index的都算作不...
package LeetCode_1358 /** * 1358. Number of Substrings Containing All Three Characters * https://leetcode.com/problems/number-of-substrings-containing-all-three-characters/ * * Given a string s consisting only of characters a, b and c. Return the number of substrings containing at least ...
The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters. Example 1: Input: "abc" Output: 3 Explanation: Three palindromic strings: "a", "b", "c". Example 2: ...
Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa". 写个判断回文字符串的函数,计数。简单粗暴。 classSolution{public:intcountSubstrings(string s){vector<char>str(s.size(),'0');for(inti=0;s[i]!='\0';i++){str[i]=s[i];}intres=0;for(intj=0;j<str....