본문 바로가기

자바스크립트34

5.3_Javascript - Sliding Window 문제풀이 Udemy - Javascript - Sliding Window Sliding Window - maxSubarraySum Given an array of integers and a number, write a function called maxSubarraySum, which finds the maximum sum of a subarray with the length of the number passed to the function. Note that a subarray must consist of consecutive elements from the original array. In the first example below, [100, 200, 300] is a subarray of the origi.. 2023. 1. 7.
5.2_Javascript - Multiple Pointers 문제풀이 Udemy - Javascript - Multiple Pointers Multiple Pointers - averagePair Multiple Pointers - averagePair Write a function called averagePair. Given a sorted array of integers and a target average, determine if there is a pair of values in the array where the average of the pair equals the target average. There may be more than one pair that matches the average target. Bonus Constraints: Time: O(N).. 2023. 1. 7.
5.1_Javascript - Frequency Counter 문제풀이 Udemy - Javascript - Frequency Counter Frequency Counter Write a function called sameFrequency. Given two positive integers, find out if the two numbers have the same frequency of digits. Your solution MUST have the following complexities: Time: O(N) Sample Input: sameFrequency(182,281) // true sameFrequency(34,14) // false sameFrequency(3589578, 5879385) // true sameFrequency(22,222) // false s.. 2023. 1. 7.
4_Udemy - Javascript 일반적인 문제풀이 패턴 Udemy - Javascript 일반적인 문제풀이 패턴 빈도수 세기 패턴 다중의 입력값들을 비교할 때 유용 배열을 이용하는 것이 아닌 / 주어진 입력값을 객체 ({}) 에 넣고, 문제를 해결하는 것이다 function anagram(word1, word2) { if (word1.length !== word2.length) { return false } else if (word1.length === 0 & word2.length === 0) { return true } let anagramObject1 = {} let anagramObject2 = {} for (let word = 0; word < word1.length ; word++) { if (word1[word] in anagramObject1).. 2023. 1. 6.
3_Javascript - 문제 해결 접근법 Udemy - Javascript 문제 해결 접근법 알고리즘이란? 특정한 작업을 끝내기 위한 과정 또는 단계다 알고리즘 풀이를 더 잘 하기 문제를 해결하기 위해 계획을 짜는 것 일반적인 문제 해결 패턴을 파악하는 것 문제 해결 문제의 이해 코드를 직접 치기 전에, 문제를 이해하는 것이 중요하다 문제를 내가 이해할 수 있도록 정리를 한다 문제에 어떤 입력값이 들어가는가? 내가 짠 코드를 통해 어떤 결과가 나오는지 생각한다 입력값이 있으면, 결과가 잘 나오는가? 데이터를 어떻게 표시할 것인가? 구체적 예제들 쉬운 예제들을 먼저 써놓은다 그리고 그보다 더 어려운 예제들로 진행한다 입력값이 없는 상태에서도 어떻게 결과나 나오는지 생각해본다 유효하지 않은 입력값을 넣어본다 세부 분석 문제에 대한 단계들을 실제로 .. 2023. 1. 5.
2_Javascript - 객체와 배열의 빅오 Udemy - Javascript 객체의 빅오 let instructor = { firstName : "Kelly", isInstructor: true, favoriteNumbers: [1,2,3,4], } Key와 Value가 있다 객체를 사용할 때 정렬이 필요하지 않을 때 데이터를 빠르게 접근을 하거나, 추가를 하거나, 삭제를 할 때 객체의 빅오 추가하기 (Insertion) : O(1) 삭제하기 (Removal) : O(1) 찾기 (Searching) : O(N) Value를 찾는 것 데이터에 접근하기 (Access) : O(1) 객체의 메서드 (Object Methods) object.keys : O(N) object.values : O(N) object.entries : O(N) hasOwnPr.. 2023. 1. 5.
1_Javascript - Big O Notation Udemy - Javascript Big O Notation 다양한 코드가 있으면, 코드의 성능을 보여주는 것 데이터가 더 많아질 수록, 코드의 성능이 매우 중요해진다 성능이 좋은 코드? addUpTo 예시) n 이 주어지면 1부터 n까지의 합을 구하는 것4 for문을 사용하기 function addUpTo (n) { let total = 0; for (let i = 1; i 2023. 1. 4.