강의

멘토링

로드맵

Inflearn Community Q&A

hellooguy's profile image
hellooguy

asked

Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)

3. Continuous Subsequence 1 (Two Pointers Algorithm)

선생님!! 이렇게 짰는데 에러가 없는 코드일까요?

Written on

·

203

0

강의 정말 만족하면서 잘 듣고 있습니다. 감사합니다 :D

while문 하나를 써서 아래와 같이 짰는데 이게 올바른 코드인지 잘 확신이 들지 않아 질문드립니다 !

 function solution(m, arr) {
        let answer = lt = sum = index = 0;

        while (lt < arr.length) {
          if (index === arr.length) {
            lt++;
            index = lt;
            sum = 0;
            continue;
          }

          sum += arr[index++];

          if (sum === m) {
            answer++;
            lt++;
            index = lt;
            sum = 0;
          }
        }

        return answer;
      }

javascript코테 준비 같이 해요!

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

네. 잘하신 코드입니다.

hellooguy's profile image
hellooguy

asked

Ask a question