[LeetCode] 1261. Find Elements in a Contaminated Binary Tree (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명Given a binary tree with the following rules:root.val == 0For any treeNode:If treeNode.val has a value x and treeNode.left != null, then treeNode.left.val == 2 * x + 1If treeNode.val has a value x and treeNode.right != null, then treeNode.right.val == 2 * x + 2Now the binary tree is contaminated, which means all treeNode.val have been changed to -1. Implement the FindElements cla..
[LeetCode] 827. Making A Large Island (Python)
·
알고리즘/LeetCode
난이도: Hard문제 설명You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applying this operation. An island is a 4-directionally connected group of 1s. 문제 예제Example 1:Input: grid = [[1,0],[0,1]] Output: 3 Explanation: Change one 0 to 1 and connect two 1s, then we get an island with area = 3. Example 2:Input: gri..
[LeetCode] 785. Is Graph Bipartite? (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. More formally, for each v in graph[u], there is an undirected edge between node u and node v. The graph has the following properties:There are no self-edges (graph[u] does not contain u).There a..
[LeetCode] 2658. Maximum Number of Fish in a Grid (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given a 0-indexed 2D matrix grid of size m x n, where (r, c) represents:A land cell if grid[r][c] = 0, orA water cell containing grid[r][c] fish, if grid[r][c] > 0.A fisher can start at any water cell (r, c) and can do the following operations any number of times:Catch all the fish at cell (r, c), orMove to any adjacent water cell.Return the maximum number of fish the fis..
[LeetCode] 1462. Course Schedule IV (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명 There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course ai first if you want to take course bi.For example, the pair [0, 1] indicates that you have to take course 0 before you can take course 1.Prerequisites can also be indirect. If cours..
[LeetCode] 802. Find Eventual Safe States (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명There is a directed graph of n nodes with each node labeled from 0 to n - 1. The graph is represented by a 0-indexed 2D integer array graph where graph[i] is an integer array of nodes adjacent to node i, meaning there is an edge from node i to each node in graph[i]. A node is a terminal node if there are no outgoing edges. A node is a safe node if every possible path starting fro..