[leetcode, JS] 3042. Count Prefix and Suffix Pairs I

mxxn·2024년 7월 18일
0

leetcode

목록 보기
188/198

문제

문제 링크 : Count Prefix and Suffix Pairs I

풀이

/**
 * @param {string[]} words
 * @return {number}
 */
var countPrefixSuffixPairs = function(words) {
    let count = 0;
    for (let i = 0; i < words.length; i++) {
        for (let j = i +1; j < words.length; j++) {
            if (words[j].startsWith(words[i]) && words[j].endsWith(words[i]) ) {
                count++
            }
        }
    }
    return count;
};
  1. 이중 for문을 통해
  2. words의 j번째 문자열들이 words의 i번째 문자열로 시작하거나 끝나는지 count
  3. count return
  • Runtime 60 ms, Memory 49.28 MB
profile
내일도 글쓰기

0개의 댓글