Coding Test/Leet Code

문제 A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker. Implement the Trie class: - Trie() Initializes the trie object. - void insert(String word) Inserts the string word into the trie. - boolean search(String word) Ret..
문제 Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree. Example 1: Input: root = [4,2,6,1,3] Output: 1 Example 2: Input: root = [1,0,48,null,null,12,49] Output: 1 Binary Search Tree가 주어진다. 여기서 각 값의 차이 중 가장 작은 값을 리턴한다. 풀이 1 각 노드의 값의 차이 중 가장 작은 값을 구하는 문제이다. 각 원소를 오름차순으로 정렬한 뒤 차이값을 구하여 풀어보려고한다. 1. 각 원소들을 우선순위..
문제 Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. If there is no such subarray, return 0 instead. Example 1: Input: target = 7, nums = [2,3,1,2,4,3] Output: 2 Example 2: Input: target = 4, nums = [1,4,4] Output: 1 Example 3: Input: target = 11, nums = [1,1,1,1,1,1,1,1] Output: 0 Constra..
문제 You are given an integer array prices where prices[i] is the price of a given stock on the ith day. On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, you can buy it then immediately sell it on the same day. Find and return the maximum profit you can achieve. Example 1: Input: prices = [7,1,5,3,6,4] Output: 7 Exampl..
문제 You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last index, or false otherwise. Example 1: Input: nums = [2,3,1,1,4] Output: true Example 2: Input: nums = [3,2,1,0,4] Output: false Constraints: 1 4 예제 2: 0 -> 1, 2, 3 1 -> 2, 3 2 -> ..
moseoh
'Coding Test/Leet Code' 카테고리의 글 목록