본문 바로가기

전체 글

(185)
LeetCode: 99번 (Recover Binary Search Tree) [JAVA] 문제 링크 https://leetcode.com/problems/recover-binary-search-tree/ Recover Binary Search Tree - LeetCode Can you solve this real interview question? Recover Binary Search Tree - You are given the root of a binary search tree (BST), where the values of exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure. Ex leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 노드들을 저..
백준: 27890 (문자열 게임) [JAVA] 문제 링크 https://www.acmicpc.net/problem/27980 27980번: 문자열 게임 첫째 줄에 보드의 길이와 건덕이가 가지고 있는 문자열의 길이를 나타내는 정수 $N, M$이 공백으로 구분되어 주어진다. $( 2 \le N, M \le 5\,000 )$ 둘째 줄에는 보드의 문자가 순서대로 주어진다. 셋째 www.acmicpc.net 풀이 전체적인 풀이 과정은 다음과 같다. 보드의 문자와, 가지고 있는 문자열을 입력 받고 dp용 2중 배열을 생성 탐색 함수를 구현 (인자의 경우 보드의 문자와 문자열, 그리고 각각의 특정 위치를 담당하는 인덱스) 1) 문자열이 끝에 도달했다면 0 반환 (기저조건) 2) 기존의 연산값이 존재한다면 해당 값 반환 3) 보드에서 왼쪽에 갈 수 있다면, 탐색 ..
백준: 12869번 (뮤탈리스크) [JAVA] 문제 링크 https://www.acmicpc.net/problem/12869 12869번: 뮤탈리스크 1, 3, 2 순서대로 공격을 하면, 남은 체력은 (12-9, 10-1, 4-3) = (3, 9, 1)이다. 2, 1, 3 순서대로 공격을 하면, 남은 체력은 (0, 0, 0)이다. www.acmicpc.net 풀이 전체적인 풀이 과정은 다음과 같다. 체력을 저장할 배열(길이 3), 그리고 dp에 사용할 3중 배열 초기화 이후 dp 기반 완전탐색 함수를 생성(인자 hp 3개) 1) 현재 인자로 들어온 hp 3개가 모두 0이하라면, 0반환 2) 해당 상황에 대한 계산 결과가 이미 존재한다면 해당 값 반환 3) 3개의 hp에 대해 공격을 했을 때 발생할 수 있는 모든 경우의 수를 확인해, 최적의 값 확인 ..
LeetCode: 98번 (Validate Binary Search Tree) [JAVA] 문제 링크 https://leetcode.com/problems/validate-binary-search-tree/ Validate Binary Search Tree - LeetCode Can you solve this real interview question? Validate Binary Search Tree - Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: * The left subtree of a node contains only nodes with keys le leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 큐..
LeetCode: 97번 (Interleaving String) [JAVA] 문제 링크 https://leetcode.com/problems/interleaving-string/ Interleaving String - LeetCode Can you solve this real interview question? Interleaving String - Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2. An interleaving of two strings s and t is a configuration where s and t are divided into n and m subs leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 우선 받은 문자열 s1, s2,..
LeetCode: 96번 (Unique Binary Search Trees) [JAVA] 문제 링크 https://leetcode.com/problems/unique-binary-search-trees/ Unique Binary Search Trees - LeetCode Can you solve this real interview question? Unique Binary Search Trees - Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n. Example 1: [https://assets.leetcode leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. dp를 사용..
LeetCode: 95번 (Unique Binary Search Trees II) [JAVA] 문제 링크 https://leetcode.com/problems/unique-binary-search-trees-ii/ Unique Binary Search Trees II - LeetCode Can you solve this real interview question? Unique Binary Search Trees II - Given an integer n, return all the structurally unique BST's (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the answer in any order. Examp leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. ..
LeetCode: 93번 (Restore IP Addresses) [JAVA] 문제 링크 https://leetcode.com/problems/restore-ip-addresses/