강의

멘토링

커뮤니티

Inflearn Community Q&A

yujuck's profile image
yujuck

asked

Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)

4. Text distance

이렇게 풀어도 괜찮을까요?

Written on

·

171

0

function solution(s, t){
    const answer = [];

    for (let x of s.split('e')) {
        const res = [];
        for(let i = 0; i < x.length/2; i++) {
            res[i] = res[x.length - 1 - i] = i + 1;
        }

        answer.push(res.join(''));
    }
    return answer.join('0');
}

let str="teachermode";
console.log(solution(str, 'e'));

 

 

이렇게 풀어보았는데 혹시 문제가 있을까요?
javascript코테 준비 같이 해요!

Answer 1

1

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

반례입니다.

console.log(solution("abceleeacode", "e"));
yujuck's profile image
yujuck

asked

Ask a question