본문 바로가기

2. 알고리즘 공부/JAVA 리트코드 풀이

(6)
[Leetcode] 221. Maximal Square https://leetcode.com/problems/maximal-square/ Maximal Square - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. Problem Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area. 2. Algorithm class Solution { public int maxi..
[LeetCode] 923. 3Sum With Multiplicity https://leetcode.com/problems/3sum-with-multiplicity/ 3Sum With Multiplicity - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. Problem Given an integer array A, and an integer target, return the number of tuples i, j, k such that i < j < k and A[i] + A[j] + A[k] == target. As th..
[Leetcode] 82. Remove Duplicates from Sorted List II https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ Loading... Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. Problem Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Input: 1->2->3->3->4->4-..
[Leetcode] 300. Longest Increasing Subsequence https://leetcode.com/problems/longest-increasing-subsequence/ 불러오는 중입니다... 1. Problem Given an unsorted array of integers, find the length of longest increasing subsequence. 2. Algorithm I used dp solution with time complexity O(n^2). Step 1. Iterate index i 0 to length of array. -> O(n) Step 2. With index j find the longest length before d[i] iteratively, where nums[i] > nums[j]. -> O(n) Step 3..
[LeetCode] 236. Lowest Common Ancestor of a Binary Tree https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ 불러오는 중입니다... 1. Problem 이진트리가 주어졌을 때, 두 개의 주어진 노드 p, q의 가장 작은 공통 조상 노드를 찾아라. Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. 2. Algorithm 나는 p, q의 공통 조상 노드라는 것은 해당 노드를 root로 하고 탐색을 하면, p, q를 모두 찾을 수 있다는 것을 뜻한다고 생각했다. 이것은 즉 트리에서 해당 노드를 기준으로 자손 노드 중에 p, q가 존재한다는 의미. 따라서 root부터 dfs로 모든 ..
[Leetcode] 347. Top K Frequent Elements https://leetcode.com/problems/top-k-frequent-elements/ Loading... Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. Problem 비어있지 않은 정수 배열이 주어졌을 때, 가장 많이 등장하는 k개의 원소를 반환하라 Given a non-empty array of integers, return the k most frequent elements. 2. Algorithm Step 1. 배열이 주어지면, 각 원소가 등장하는 횟수를..