코딩 (85) 썸네일형 리스트형 LeetCode: 200번 (Number of Islands) [JAVA] 문제 링크 https://leetcode.com/problems/number-of-islands/ Number of Islands - 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 풀이 전체적인 풀이 과정은 다음과 같다. 반환할 answer 값 0으로 초기화 bfs 기반으로 주어진 grid를 탐색, 전체 grid를 돌며 해당 위치가 '1'인 경우 큐에 해당 위치를 넣고 bfs를 진행하여 현재 '1'과 연결된 위치의 값들을 모두 찾아 '0'으로 초기화한다. 이후 .. LeetCode: 322번 (Coin Change) [JAVA] 문제 링크 https://leetcode.com/problems/coin-change/ Coin Change - 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 풀이 전체적인 풀이 과정은 다음과 같다. 주어진 amount 값 + 1만큼의 dp용 배열 전체 -1값으로 초기화, dp[0]의 경우 0으로, 그리고 주어진 coins 배열 속 값들을 인덱스로한 dp의 요소들은 1로 초기화 재귀호출 기반으로 dp 함수를 작성. 인자는 coins 배열과 남은 돈의 양을 나타내.. LeetCode: 300번 (Longest Increasing Subsequence) [JAVA] 문제 링크 https://leetcode.com/problems/longest-increasing-subsequence/ Longest Increasing Subsequence - 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 풀이 전체적인 풀이 과정은 다음과 같다. 주어진 nums 배열 길이만큼의 dp용 배열 초기화, 마지막 요소는 값을 1로 초기화 (가질 수 있는 최대 길이가 1이기 때문) 배열의 끝에서부터 앞으로 for문을 돌며, 해당 요소보다 뒤에 있는 .. LeetCode: 10번 (Regular Expression Matching) [JAVA] 문제 링크 https://leetcode.com/problems/regular-expression-matching/ Regular Expression Matching - 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 풀이 전체적인 풀이 과정은 다음과 같다. 주어진 문자열 s와 패턴 p의 매치 여부를 판별하는 함수를 재귀함수로 작성 기저 조건의 경우 패턴의 문자열이 비었을 때 주어진 문자열 s가 비었다면 true를 반환하고 그렇지 않다면 false 반환 주어진 패.. LeetCode: 14번 (Longest Common Prefix) [JAVA] 문제 링크 https://leetcode.com/problems/longest-common-prefix/ Longest Common Prefix - 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 풀이 전체적인 풀이 과정은 다음과 같다. 주어진 strs 배열의 첫 번째 요소를 가져온 후 해당 단어가 가진 접두사 모음을 모두 HashSet에 저장 그 이후 요소들을 돌며 현재 HashSet 속 접두사들과 비교를 하며 맞지 않은 접두사들의 경우 HashSet에서 삭제 .. LeetCode: 39번 (Combination Sum) [JAVA] 문제 링크 https://leetcode.com/problems/combination-sum/ Combination Sum - 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 풀이 전체적인 풀이 과정은 다음과 같다. 완전탐색을 기반으로 target에 대해 가능한 조합을 만드는 함수를 재귀호출을 바탕으로 작성 인자는 candidates 배열과 target 중 현재 남은 값을 나타내는 remain 값, candidates 배열 중 현 위치를 나타내는 index 값 기.. LeetCode: 22번 (Generate Parentheses) [JAVA] 문제 링크 https://leetcode.com/problems/generate-parentheses/ Generate Parentheses - 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 풀이 전체적인 풀이 과정은 다음과 같다. 주어진 숫자 n에 대하여 만들 수 있는 조합을 만드는 함수를 재귀호출을 바탕으로 작성 현재 구성 상 양쪽 괄호 쌍의 개수가 동일하다면 다음에는 무조건 왼쪽 괄호만 추가 왼쪽 괄호가 더 많다면 왼쪽 괄호를 추가하거나 오른쪽 괄호를 추가.. LeetCode: 12번 (Integer to Roman) [JAVA] 문제 링크 https://leetcode.com/problems/integer-to-roman/ Integer to Roman - 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 풀이 전체적인 풀이 과정은 다음과 같다. 주어진 수에 대해 1000의 자릿수에 대해 개수를 카운트해 문자 formatting 그 하위 숫자들에 대해선 경우의 수 (0~3, 4, 5~8, 9)를 구분지어 문자를 formatting할 수 있는 함수를 통해 문자열 생성 단순 주어진 문자를 이어.. 이전 1 2 3 4 ··· 11 다음