목록문자열 (72)
N
https://school.programmers.co.kr/learn/courses/30/lessons/118666?language=javascript 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 주어진 조건대로 맵핑을 진행하면 쉽게 풀 수 있다. 성격 유형의 각 지표는 사전순으로 주어졌기 때문에 그대로 array에 저장. 성격의 점수를 저장하기 위한 map도 선언한다. survey를 순회하면서 점수를 구한다. front와 back으로 문자열을 두 개의 문자로 나눈다. 또한, choice[i]의 점수로 어느 성격 지표에 점수를 더할지 정한다. 만약 4..
https://leetcode.com/problems/repeated-substring-pattern/ Repeated Substring Pattern - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문자열 패턴 찾기 문제. 이중 for문으로 쉽게 해결할 수 있다. 먼저 pattern을 0번째 인덱스부터 i번째 인덱스까지 자른다. 그리고 isRepeated라는 flag를 설정하고, 내부 for문이 모두 돌게 되면 isRepated는 바뀌지 않아 패턴 문자열이라..
https://leetcode.com/problems/add-strings/ Add Strings - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문자열로 이뤄진 두 수를 더한 값을 문자열로 다시 리턴하면 된다. 각 자리수를 number형으로 바꾸고 더한 값을 answer 배열에 push하는 과정이다. 먼저 두 수의 자릿수를 맞춘다. num1과 num2의 길이를 비교하여 더 작은 길이를 num1으로 바꿔준다. 이후 num1은 num2의 길이만큼 0을 앞에 붙여..
https://leetcode.com/problems/letter-combinations-of-a-phone-number/ Letter Combinations of a Phone Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 각 번호에 맵핑된 문자의 모든 조합을 찾아내는 문제. 완전 탐색으로 풀이. dfs에 넘겨주는 인자는 (현재 문자열, 현재 digits의 인덱스, 현재 문자의 길이)다. dfs 함수. 우선 digits[index]를 numbe..
https://programmers.co.kr/learn/courses/30/lessons/60060 코딩테스트 연습 - 가사 검색 programmers.co.kr Trie 알고리즘 활용. 물음표가 쿼리의 앞에 존재하는지, 뒤에 존재하는지에 따라 Trie 탐색을 다르게 해야 한다. 2가지의 Trie를 선언하여 단어를 저장하는데, 앞에서 단어를 검색하는 경우와 뒤에서 단어를 검색하는 경우를 저장하기 위함이다. 각 Trie를 frontTrie, backTrie라는 이름으로 선언했다. 우선 words에 있는 단어를 중복제거를 하여 newWords에 저장한다. newWords 배열을 순회하면서 단어를 frontTrie와 backTrie에 저장한다. backTrie에 저장하기 위해서는 단어를 뒤집어야 하기 때문에..
https://leetcode.com/problems/letter-case-permutation/ Letter Case Permutation - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 백트랙킹 활용. dfs() 함수에 s와 시작 인덱스 0을 넘겨 시작한다. 만약 i === s.length와 같다면 answer에 지금까지 진행한 문자열 s를 넣고 종료한다. 그렇지 않다면 계속 문자열을 탐색한다. 현재 i번째 인덱스가 문자라면 대문자로 바꾸거나 소문자로 바꿔..
https://leetcode.com/problems/find-and-replace-in-string/ Find And Replace in String - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문자열과 hash map을 활용. indices 배열이 오름차순으로 정렬되어있지 않다. 그래서 인덱스에 따른 source와 target을 map에 저장 후 문자열을 변환하면 된다. map에 저장 후 indices를 오름차순으로 정렬 후, s 문자열을 순회 만약 i..
https://leetcode.com/problems/rearrange-spaces-between-words/submissions/ Rearrange Spaces Between Words - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com /** * @param {string} text * @return {string} */ const reorderSpaces = (text) => { let space = 0; let string = ""; const splite..