[leetcode, JS] 1624. Largest Substring Between Two Equal Characters

mxxn·2023년 10월 30일
0

leetcode

목록 보기
107/198

문제

문제 링크 : Largest Substring Between Two Equal Characters

풀이

/**
 * @param {string} s
 * @return {number}
 */
var maxLengthBetweenEqualCharacters = function(s) {
    let out=-1
    for(let i=s.length-1;i>0;i--){
        let holder=s.indexOf(s[i])
        out=Math.max(out,i-(holder+1))
    }


    return out
};
  1. for문을 뒤에서부터 시작하고, indexOf로 같은 문자를 찾아 가장 긴 길이를 구하는 방식
  • Runtime 58ms, Memory 42.17MB
profile
내일도 글쓰기

0개의 댓글