강의

멘토링

커뮤니티

Inflearn Community Q&A

jay0's profile image
jay0

asked

Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)

3. Continuous Subsequence 1 (Two Pointers Algorithm)

반례가 없는지, 시간복잡도는 괜찮은지 궁금합니다!

Resolved

Written on

·

368

0

const sol = (arr, n) => {
  let p1 = 0,
    cnt = 0;

  while (p1 < arr.length) {
    arr.slice(p1++).reduce((acc, cur) => {
      const result = acc + cur;
      if (result === n) cnt++;
      return result;
    }, 0);
  }

  const answer = cnt;
  return answer;
};
javascript코테 준비 같이 해요!

Answer 1

0

000 Jay님의 프로필 이미지
000 Jay
Questioner

아.. 이건 n^2이군요

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

네. 맞습니다.

jay0's profile image
jay0

asked

Ask a question