-
Notifications
You must be signed in to change notification settings - Fork 250
Open
Labels
LeetcodeLeetcode的题目Leetcode的题目
Description
/**
* @param {string} s
* @return {number}
*/
var countSubstrings = function(s) {
let len = s.length,
count = 0;
for(let i=0; i<len; i++) {
for(let j=len-i; j>0; j--) {
let sub = s.substr(i, j); //i起始位置,j提取数量
if(isValid(sub)) {
count++;
}
}
}
return count;
};
function isValid(str) {
let len = str.length;
if(len == 1 || len == 0) {
return true;
}
let start = str[0],
end = str[len - 1];
if(start != end) {
return false;
}
return isValid(str.substr(1, len-2));
}Metadata
Metadata
Assignees
Labels
LeetcodeLeetcode的题目Leetcode的题目