[LeetCode] 2467. Most Profitable Path in a Tree (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. At every node i, there is a gate. You are also given an array of even integers amount, where amount[i] represents:the price needed to open the gate ..
[LeetCode] 1028. Recover a Tree From Preorder Traversal (Python)
·
알고리즘/LeetCode
난이도: Hard문제 설명We run a preorder depth-first search (DFS) on the root of a binary tree. At each node in this traversal, we output D dashes (where D is the depth of this node), then we output the value of this node.  If the depth of a node is D, the depth of its immediate child is D + 1.  The depth of the root node is 0. If a node has only one child, that child is guaranteed to be the left child. ..
[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] 1980. Find Unique Binary String (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명Given an array of strings nums containing n unique binary strings each of length n, return a binary string of length n that does not appear in nums. If there are multiple answers, you may return any of them. 문제 예제Example 1:Input: nums = ["01","10"]Output: "11"Explanation: "11" does not appear in nums. "00" would also be correct.Example 2:Input: nums = ["00","01"]Output: "11"Expla..
[LeetCode] 1415. The k-th Lexicographical String of All Happy Strings of Length n (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명A happy string is a string that:consists only of letters of the set ['a', 'b', 'c'].s[i] != s[i + 1] for all values of i from 1 to s.length - 1 (string is 1-indexed).For example, strings "abc", "ac", "b" and "abcbabcbcb" are all happy strings and strings "aa", "baa" and "ababbc" are not happy strings. Given two integers n and k, consider a list of all happy strings of length n so..
[LeetCode] 2375. Construct Smallest Number From DI String (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given a 0-indexed string pattern of length n consisting of the characters 'I' meaning increasing and 'D' meaning decreasing. A 0-indexed string num of length n + 1 is created using the following conditions:num consists of the digits '1' to '9', where each digit is used at most once.If pattern[i] == 'I', then num[i] .If pattern[i] == 'D', then num[i] > num[i + 1].Return th..