본문 바로가기
728x90
반응형

Algorithm134

[LeetCode] Search a 2D Matrix 문제 You are given an m x n integer matrix matrix with the following two properties:Each row is sorted in non-decreasing order.The first integer of each row is greater than the last integer of the previous row.Given an integer target, return true if target is in matrix or false otherwise.You must write a solution in O(log(m * n)) time complexity.  Example 1:Input: matrix = [[1,3,5,7],[10,11,16,20].. 2024. 6. 4.
[LeetCode] 221. Maximal Square 문제 Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area. Example 1:Input: matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]Output: 4 Example 2: Input: matrix = [["0","1"],["1","0"]]Output: 1    내 생각 1로 구성된 정사각형의 넓이를 구하는 문제이다. dp를 사용해서 풀면된다!현재 위치의 값이 '1'인 경우에 가능한 가장 큰 정사각형의 변의 길이를 계산한.. 2024. 6. 2.
[LeetCode] 215. Kth Largest Element in an Array 문제 Given an integer array nums and an integer k, return the kth largest element in the array.Note that it is the kth largest element in the sorted order, not the kth distinct element.Can you solve it without sorting?  Example 1:Input: nums = [3, 2, 1, 5, 6, 4], k = 2Output: 5    내 생각 주어진 정수 배열에서 k번쨰로 큰 요소를 찾는 문제이다. 첫번째는 정렬을 이용하였는데, 더 알아보다가 정렬보다 최소 힙이 더 효율적이라고 하여 최소 힙으로도 구현해보았다.모든 배열을 힙에 추가하고, 힙의.. 2024. 5. 31.
[LeetCode] 22. Generate Parentheses 문제 Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1:Input: n = 3Output: ["((()))","(()())","(())()","()(())","()()()"] Example 2:Input: n = 1Output: ["()"]     내 생각 문제 요약주어진 'n' 의 괄호의 쌍을 조합하여 광호 조합을 생성하는 문제이다.1. 여는 괄호'(' 의 개수와 닫는 괄호 ')'의 개수가 같다.2. 닫는 괄호의 개수  백트래킹을 이용한 풀이로 가능한 모든 조합을 탐색(괄호 조합)하면서 조건에 맞는 조합을 선택한다. 종료 조건 '('의 개수와 ')'의.. 2024. 5. 28.
728x90
반응형