알고리즘 7

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

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

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

Sliding window

Sliding window란? This pattern involves creating a window which can either be an array or number from one position to another. Depending on a certain condition, the window either increases or closes(and a new window is created) Very useful for keeping track of a subset of data in an array/string. 이 패턴은 한 위치에서 다른 위치로 배열 또는 숫자가 될 수 있는 창을 만드는 것을 포함합니다. 특정 조건에 따라 창이 커지거나 닫힙니다(새 창이 생성됨). 배열/문자열에 있는 데이..

알고리즘 2022.07.10

[알고리즘]strs은 단어가 담긴 배열 공통된 시작 단어(prefix)를 반환

strs은 단어가 담긴 배열입니다. 공통된 시작 단어(prefix)를 반환해주세요. 예를 들어 strs = ['start', 'stair', 'step'] return은 'st' strs = ['start', 'wework', 'today'] return은 '' 마지막 줄은 문제가 덜 쓰인건 줄 알았는데, 그게아니라 공통된 시작 단어가 없는 경우에는 '', 즉 빈 문자열을 반환하라는 이야기였다. 함께 리뷰해준 팀원분의 코드를 보면, const getPrefix = strs => { let answer=[]; if (strs[0]===undefined){ return "" } for (i=0; i< strs.length; i++){ for (j=1; j { let answer=[]; if (strs[0]=..

알고리즘 2022.05.28

[알고리즘] 중복되지 않은 알파벳으로 이루어진 제일 긴 단어의 길이 구하기

String 형인 str 인자에서 중복되지 않은 알파벳으로 이루어진 제일 긴 단어의 길이를 반환해주세요. str: 텍스트 return: 중복되지 않은 알파벳 길이 (숫자 반환) 예를 들어, str = "abcabcabc" return 은 3 => 'abc' 가 제일 길기 때문 str = "aaaaa" return 은 1 => 'a' 가 제일 길기 때문 str = "sttrg" return 은 3 => 'trg' 가 제일 길기 때문 알파벳의 길이를 반환해야하니, .length를 써야겠다는 것 외에 감이 안와 구글링을 해보았다. 아래 풀이를 공부하는 걸로 대신한다. longest substring of non repeating characters javascript - Stack Overflow 배열을 발견..

알고리즘 2022.05.26