강의

멘토링

로드맵

Inflearn Community Q&A

wlstjrghdud5725's profile image
wlstjrghdud5725

asked

Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)

1. Merging two arrays (Two Pointers Algorithm)

올바른 방향인지 질문드립니다.

Written on

·

217

0

- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요!
- 먼저 유사한 질문이 있었는지 검색해보세요.
- 서로 예의를 지키며 존중하는 문화를 만들어가요.
- 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.
 
안녕하세요
비슷하면서도 slice와 map을 이용해서 문제를 풀었는데
시간복잡도상으로 slice가 들어가면서 더 좋지 않은 방식으로 풀게 된걸까요?
function solution(arr1,arr2){
let answer =[];
let n=0,m=0;
while(true){

if(arr1[n]<arr2[m])
{ answer.push(arr1[n])
n++
if(n>=arr1.length){
arr2.slice(m,).map(data=>answer.push(data))
break;
}
}
else{
answer.push(arr2[m])
m++
if(m>=arr2.length){
arr1.slice(n,).map(data=>answer.push(data))
break;
}
}



}

return answer;

}
javascript코테 준비 같이 해요!

Quiz

What is the main reason why two-pointer or sliding window techniques are more efficient than nested loops?

Because it uses less memory?

Is it because the code is shorter?

Is it because it achieves O(N) time complexity in most cases?

Is it because it's not affected by the input data size?

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

영상에서 설명한 방식을 꼭 익히셨으면 합니다.

wlstjrghdud5725's profile image
wlstjrghdud5725

asked

Ask a question