[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.