알고리즘 25

Searching algorithme

문자열로 된 배열에서 문자열을 찾는 알고리즘 indexOf로 접근 가능한 것이 있으면 index 반환, 없으면 -1 반환 이걸 어떻게 메서드 사용하지 않고 알고리즘으로 하는지? 목적 describe what is a searching algorithm is implement linear search on arrays implement binary search on sorted arrays implement a naive string searching algorithm implement the KMP string searching algorithm Knuth–Morris–Pratt algorithm 1. Linear search on arrays It is the simplest way Search for..

알고리즘 2022.11.13

[재귀] someRecursive

문제 Write a recursive function called someRecursive which accepts an array and a callback. The function returns true if a single value in the array returns true when passed to the callback. Otherwise it returns false. 배열과 콜백을 받는 someRecursive라는 재귀 함수를 작성하십시오. 콜백에 전달할 때 배열의 단일 값이 true를 반환하면 함수는 true를 반환합니다. 그렇지 않으면 false를 반환합니다. // SAMPLE INPUT / OUTPUT // const isOdd = val => val % 2 !== 0; // so..

알고리즘 2022.10.31

재귀: power 제곱, factorial 계승

Write a function called power which accepts a base and an exponent. The function should return the power of the base to the exponent. This function should mimic the functionality of Math.pow() - do not worry about negative bases and exponents. 베이스와 지수를 받아들이는 거듭제곱이라는 함수를 작성하십시오. 함수는 베이스의 거듭제곱을 지수로 반환해야합니다. 이 기능은 Math.pow ()의 기능을 모방해야합니다. function power(base, exponent) { if (exponent === 0) return..

알고리즘 2022.09.03

Recursion 재귀

재귀란? -A a function that calls itself. 자신을 호출하는 함수 언제 사용하는지? -JSON.parse/ JSON.stringify -document.getElementById and DOM traversal algorithms -Object traversal -more complex data structures -cleaner alternative to iteration 호출 스택 1. Call stack 호출 스택 -it's a stack data structure -Any time a function is invoked it is placed (pushed) on the top of the call stack. 함수가 호출될 때마다 호출 스택의 맨 위에 배치(푸시)됩니다. ..

알고리즘 2022.08.15

[Sliding window] minSubArrayLen

문제 Write a function called minSubArrayLen which accepts two parameters - an array of positive integers and a positive integer. This function should return the minimal length of a contiguous subarray of which the sum is greater than or equal to the integer passed to the function. If there isn't one, return 0 instead. 양의 정수 배열과 양의 정수라는 두 개의 매개변수를 받는 minSubArrayLen이라는 함수를 작성하세요. 이 함수는 합이 함수에 전달된 정수..

알고리즘 2022.08.07

알고리즘 문제풀이 접근 방법

Algorithm: process, set of steps to accomplish a certain task How to you improve 1.devise a plan for solving problem 2.master common problem solving patterns Problem solving 1.understand the problem 2.explore concrete examples 3.break it down 4.solve/simplify 5.look back and refactor 1. 문제 이해 2. 구체적인 사례 탐색 3. 작업을 나누기 4. 해결/단순화 5. 돌아보고 리팩토링 How 1.understand the problem -1.can I restate the proble..

알고리즘 2022.08.07

[Multiple pointers] isSubsequence

Wirte a function called isSubsequence which takes two strings and checks whether the characters in the first string from a subsequence of the characters in the second string. In other words, the function should check whether the characters in the first string appear somewhere in the second string, without their order changing. 두 개의 문자열을 가져와서 첫 번째 문자열의 문자가 두 번째 문자열에 있는 문자의 하위 시퀀스인지 확인하는 isSubsequ..

알고리즘 2022.07.31