알고리즘

✨ 문제 Count Negative Numbers in a Sorted Matrix Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You must write an algorithm with O(log n) runtime complexity. Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number..
✨ 문제 Search Insert PositionGiven a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You must write an algorithm with O(log n) runtime complexity. https://leetcode.com/problems/search-insert-position/description/   ✨ 개념이진탐색 Binary Search-   ✨ 최종코드class Solution { public int sea..
✨ 문제 Divisor GameAlice and Bob take turns playing a game, with Alice starting first.Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of:Choosing any x with 0 Replacing the number n on the chalkboard with n - x.Also, if a player cannot make a move, they lose the game.Return true if and only if Alice wins the game, assuming both players p..
✨ 문제 Fibonacci NumberGiven an integer numRows, return the first numRows of Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,F(0) = 0, F(1) = 1F(n) = F(n -..
✨ 문제 Pascal's TriangleGiven an integer numRows, return the first numRows of Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it as shown: https://leetcode.com/problems/pascals-triangle/description/   ✨ 개념동적 프로그래밍 Dynamic Programming- 복잡한 문제를 작은 문제로 분해하여 해결하는 알고리즘 기법.- 동적 프로그래밍을 적용하기 위해서는 다음 2가지 조건이 필요하다.최적 부분 구조 : 전체 문제의 최적해를 부분 문제의 최적해로부터  찾을 수 있어..
✨ 문제 Counting BitsGiven an integer n, return an array ans of length n + 1 such that for each i (0 ), ans[i] is the number of 1's in the binary representation of i. https://leetcode.com/problems/counting-bits/description/   ✨ 개념동적 프로그래밍 Dynamic Programming- 복잡한 문제를 작은 문제로 분해하여 해결하는 알고리즘 기법.- 동적 프로그래밍을 적용하기 위해서는 다음 2가지 조건이 필요하다.최적 부분 구조 : 전체 문제의 최적해를 부분 문제의 최적해로부터  찾을 수 있어야함.중복되는 부분 문제 : 부분 문제가 여러..
✨ 문제 Split a String in Balanced StringsBalanced strings are those that have an equal quantity of 'L' and 'R' characters.Given a balanced string s, split it into some number of substrings such that:Each substring is balancedReturn the maximum number of balanced strings you can obtain. https://leetcode.com/problems/split-a-string-in-balanced-strings/description/   ✨ 개념탐욕법 Greedy Algorithm- 현재 상황에서..
✨ 문제 체육복점심시간에 도둑이 들어, 일부 학생이 체육복을 도난당했습니다. 다행히 여벌 체육복이 있는 학생이 이들에게 체육복을 빌려주려 합니다. 학생들의 번호는 체격 순으로 매겨져 있어, 바로 앞번호의 학생이나 바로 뒷번호의 학생에게만 체육복을 빌려줄 수 있습니다. 예를 들어, 4번 학생은 3번 학생이나 5번 학생에게만 체육복을 빌려줄 수 있습니다. 체육복이 없으면 수업을 들을 수 없기 때문에 체육복을 적절히 빌려 최대한 많은 학생이 체육수업을 들어야 합니다. 전체 학생의 수 n, 체육복을 도난당한 학생들의 번호가 담긴 배열 lost, 여벌의 체육복을 가져온 학생들의 번호가 담긴 배열 reserve가 매개변수로 주어질 때, 체육수업을 들을 수 있는 학생의 최댓값을 return 하도록 solution ..
✨ 문제 Maximum Depth of Binary TreeGiven the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.  https://leetcode.com/problems/maximum-depth-of-binary-tree/description/   ✨ 개념이진 트리- 분할 정복 탐색 알고리즘으로 빠른 속도로 탐색 가능- 모든 노드가 2개의 서브 트리를 갖는 트리. 서브트리는 공집합일 수 있음.- 모든 노드가 최대 2개의 자식 노드가..
✨ 문제 Invert Binary TreeGiven the root of a binary tree, invert the tree, and return its root. https://leetcode.com/problems/invert-binary-tree/description/   ✨ 개념이진 트리- 분할 정복 탐색 알고리즘으로 빠른 속도로 탐색 가능- 모든 노드가 2개의 서브 트리를 갖는 트리. 서브트리는 공집합일 수 있음.- 모든 노드가 최대 2개의 자식 노드가 존재할 수 있음.- 모든 노드의 차수가 2 이하.- 이진 트리에는 서브 트리간 순서가 존재하며 왼쪽 트리와 오른쪽 트리가 구별됨.   ✨ 최종코드/** * Definition for a binary tree node. * public clas..
yeooniyeoon
'알고리즘' 카테고리의 글 목록 (3 Page)