전체 글
-
[Algorithm] LeetCode - 229. Majority Element II, [Array, Hash, Sorting]Alogorithm 2022. 4. 18. 21:02
LeetCode 문제입니다. [문제설명] Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. 번역) 크기가 n인 정수 배열이 주어지면 ⌊ n/3 ⌋번 이상 나타나는 모든 요소를 찾습니다. Topic: Array, Hash, Sorting, Counting Level: Medium Accepted 282,193 / Submissions 668,104 [제한사항] 1 threshold) .map(item => Number(item[0])) }; Idea: 1. nums 배열에서 받은 element를 Key로 하고 count를 value로 할 object 생성 2. threshold 계산 3. tmpOb..
-
[Algorithm] LeetCode - 102. Binary Tree Level Order Traversal (BFS)Alogorithm 2022. 2. 13. 19:56
LeetCode 문제입니다. [문제설명] Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level). 번역) 이진 트리의 루트가 주어지면 노드 값의 레벨 순서 순회를 반환합니다. (즉, 왼쪽에서 오른쪽으로, 레벨별로). Topic: Tree, Breadth First Search, Binary Tree Level: Medium Accepted 1,127,671 / Submissions 1,873,375 [제한사항] The number of nodes in the tree is in the range [0, 2000]. -1000
-
[Algorithm] LeetCode - 113. Path Sum II (DFS)Alogorithm 2022. 2. 13. 19:48
LeetCode 문제입니다. [문제설명] Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum. Each path should be returned as a list of the node values, not node references. A root-to-leaf path is a path starting from the root and ending at any leaf node. A leaf is a node with no children. 번역) Binary Tree의 root와 정수 t..
-
[Algorithm] 시간 복잡도Alogorithm 2022. 1. 23. 20:54
개념 설명을 위한 글입니다. [시간복잡도] 시간복잡도 그리고 공간복잡도, 알고리즘의 성능을 나타내는 두가지 지표이다. 시간복잡도가 시간을 정량화 하는 수단 중 하나라면, 공간복잡도는 작성한 알고리즘이 얼마만큼의 리소스(메모리)를 사용하는가를 측정하는 수단이라고 볼 수 있다. 본 글에서는 시간복잡도에 대해 간단히 정리해보려고 한다. 알고리즘을 많이 푸는 것도 좋지만 방법론과 개념을 베이스로 깔고 가는것도 중요하다고 생각하는 미래의 꼰대 새싹 Wiki 컴퓨터과학에서 알고리즘의 시간복잡도는 입력을 나타내는 문자열 길이의 함수로서 작동하는 알고리즘을 취해 시간을 정량화하는 것이다. 알고리즘의 시간복잡도는 주로 빅-오 표기법을 사용하여 나타내며, 이 빅-오 표기법은 계수와 낮은 차수의 항을 제외시키는 방법이다. ..
-
[Algorithm] LeetCode - 1817. Finding the Users Active Minutes(Hash)Alogorithm 2022. 1. 23. 16:28
LeetCode 문제입니다. [문제설명] You are given the logs for users' actions on LeetCode, and an integer k. The logs are represented by a 2D integer array logs where each logs[i] = [IDi, timei] indicates that the user with IDiperformed an action at the minute timei. Multiple users can perform actions simultaneously, and a single user can perform multiple actionsin the same minute. The user active minutes (U..
-
[Algorithm] LeetCode - 1641. Count Sorted Vowel Strings(Dynamic Programming)Alogorithm 2022. 1. 23. 15:48
LeetCode 문제입니다. [문제설명] Given an integer n, return the number of strings of length n that consist only of vowels (a, e, i, o, u) and are lexicographically sorted. A string s is lexicographically sorted if for all valid i, s[i] is the same as or comes before s[i+1] in the alphabet. 번역) n이 주어졌을 때, 모음(a, e, i, o, u)로 구성되어 있고 정렬된 n 크기의 문자열 개수를 구하시오. 모든 유효한 i에 대해 s[i]가 알파벳에서 s[i+1]과 같거나 그 앞에 오는 경우 문자열..
-
[Algorithm] 프로그래머스 - 쿼드압축 후 개수 세기(분할정복)Alogorithm 2022. 1. 5. 20:30
프로그래머스 문제입니다. [문제설명] 0과 1로 이루어진 2n x 2n 크기의 2차원 정수 배열 arr이 있습니다. 당신은 이 arr을 쿼드 트리와 같은 방식으로 압축하고자 합니다. 구체적인 방식은 다음과 같습니다. 당신이 압축하고자 하는 특정 영역을 S라고 정의합니다. 만약 S 내부에 있는 모든 수가 같은 값이라면, S를 해당 수 하나로 압축시킵니다. 그렇지 않다면, S를 정확히 4개의 균일한 정사각형 영역(입출력 예를 참고해주시기 바랍니다.)으로 쪼갠 뒤, 각 정사각형 영역에 대해 같은 방식의 압축을 시도합니다. arr이 매개변수로 주어집니다. 위와 같은 방식으로 arr을 압축했을 때, 배열에 최종적으로 남는 0의 개수와 1의 개수를 배열에 담아서 return 하도록 solution 함수를 완성해주세..
-
[Algorithm] 프로그래머스 - 큰 수 만들기 (그리디)Alogorithm 2022. 1. 5. 20:26
프로그래머스 문제입니다. [문제설명] 어떤 숫자에서 k개의 수를 제거했을 때 얻을 수 있는 가장 큰 숫자를 구하려 합니다. 예를 들어, 숫자 1924에서 수 두 개를 제거하면 [19, 12, 14, 92, 94, 24] 를 만들 수 있습니다. 이 중 가장 큰 숫자는 94 입니다. 문자열 형식으로 숫자 number와 제거할 수의 개수 k가 solution 함수의 매개변수로 주어집니다. number에서 k 개의 수를 제거했을 때 만들 수 있는 수 중 가장 큰 숫자를 문자열 형태로 return 하도록 solution 함수를 완성하세요. [제한사항] number는 1자리 이상, 1,000,000자리 이하인 숫자입니다. k는 1 이상 number의 자릿수 미만인 자연수입니다. [입출력] [문제풀이] functio..