[leetcode, JS] 3083. Existence of a Substring in a String and Its Reverse

mxxn·2024년 7월 24일
0

leetcode

목록 보기
190/198

문제

문제 링크 : Existence of a Substring in a String and Its Reverse

풀이

/**
 * @param {string} s
 * @return {boolean}
 */
var isSubstringPresent = function(s) {

    for(let i = 1; i < s.length; i++) {
        let str = `${s[i]}${s[i-1]}`
        if(s.includes(str)) return true;
    }

    return false;
};
  1. for문을 통해
  2. s의 i번째와 i-1번째로 만든 string이 s에 포함되어있는지 확인
  • Runtime 67 ms, Memory 49.57 MB
profile
내일도 글쓰기

0개의 댓글