Algorithm 3

자료구조 Trie

Trie 자료구조란 입력받은 문자열들을 트리형태로 저장하는 자료구조입니다.주로 문자열 탐색이나 자동 완성 기능 등에 자주 사용됩니다. ["abc", "ab", "bc", "b", "cd"] 를 Trie자료구조로 표현해보면, 이러한 구조를 가지므로, a를 검색했을때 하위요소인 b를 자동완성기능으로 보여주고, ab를 검색했을때, 하위요소 c와 d를 추가해서 보여줄 수 있습니다. Trie자료구조를 이용하는 leetcode 문제를 소개해드리겠습니다. 14. Longest Common Prefix문자열 배열 중에서 가장 긴 공통 접두사 문자열을 찾는 함수를 작성하세요.공통적인 접두사가 없으면 빈 문자열을 반환합니다.입력: strs = ["flower","flow","flight"]출력: "fl"입력: strs =..

Algorithm 2024.09.29

LeetCode 회문 문자열 찾기

LeetCode의 5. Longest Palindromic Substring medium단계의 문제입니다. Given a string s, return the longest palindromic substring in s. Example 1:Input: s = "babad"Output: "bab"Explanation: "aba" is also a valid answer. Example 2:Input: s = "cbbd"Output: "bb" 해당 문제는 주어진 문자열 s 에서 가장 긴 회문을 찾는것입니다.회문이란 문자열을 뒤집었을 경우에도 같은것을 의미합니다.  예시) aaa, 우영우시작index와 끝index로 투포인터로 나눠서, 끝index를 하나씩 늘려가며, 모든 단어에 대해 회문검사를 실시하고, ..

Algorithm 2024.09.19

프로그래머스 달리기경주 JS

프로그래머스 LV1 달리기경주 JavaScript 순차적으로 calling의 원소에대해 players에서의 index를 찾고, players배열에서 해당index와 index-1 의 자리를 바꿔주는 방식으로 코드를 짰습니다. function solution(players, callings) { callings.map((e) => { const index = players.indexOf(e); const temp = players[index]; players[index] = players[index - 1]; players[index - 1] = temp; }); return players } 하지만 , 시간초과 발생.. 문제에선 시간제약에대해 안적혀있었는데 .. indexOf로 배열을 순회해 index를..

Algorithm 2023.11.30