[LeetCode] 2579. Count Total Number of Colored Cells (Python)
·
알고리즘/LeetCode
난이도: MediumProblem Description There exists an infinitely large two-dimensional grid of uncolored unit cells. You are given a positive integer n, indicating that you must do the following routine for n minutes:At the first minute, color any arbitrary unit cell blue.Every minute thereafter, color blue every uncolored cell that touches a blue cell.Below is a pictorial representation of the state o..
[LeetCode] 1780. Check if Number is a Sum of Powers of Three (Python)
·
알고리즘/LeetCode
난이도: MediumProblem Description Given an integer n, return true if it is possible to represent n as the sum of distinct powers of three. Otherwise, return false. An integer y is a power of three if there exists an integer x such that y == 3x. Problem ExampleExample 1:Input: n = 12Output: trueExplanation: 12 = 3^1 + 3^2Example 2:Input: n = 91Output: trueExplanation: 91 = 3^0 + 3^2 + 3^4Example 3:I..
[LeetCode] 2161. Partition Array According to Given Pivot (Python)
·
알고리즘/LeetCode
난이도: MediumProblem DescriptionYou are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied:Every element less than pivot appears before every element greater than pivot.Every element equal to pivot appears in between the elements less than and greater than pivot.The relative order of the elements less than pivot and the elemen..
[LeetCode] 2570. Merge Two 2D Arrays by Summing Values (Python)
·
알고리즘/LeetCode
난이도: EasyProblem DescriptionYou are given two 2D integer arrays nums1 and nums2.nums1[i] = [idi, vali] indicate that the number with the id idi has a value equal to vali.nums2[i] = [idi, vali] indicate that the number with the id idi has a value equal to vali.Each array contains unique ids and is sorted in ascending order by id. Merge the two arrays into one array that is sorted in ascending ord..
[LeetCode] 2460. Apply Operations to an Array (Python)
·
알고리즘/LeetCode
난이도: EasyProblem DescriptionYou are given a 0-indexed array nums of size n consisting of non-negative integers. You need to apply n - 1 operations to this array where, in the ith operation (0-indexed), you will apply the following on the ith element of nums:If nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. Otherwise, you skip this operation.After performing all the ..
[LeetCode] 1092. Shortest Common Supersequence (Python)
·
알고리즘/LeetCode
난이도: HardProblem Description Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them. A string s is a subsequence of string t if deleting some number of characters from t (possibly 0) results in the string s. Problem ExampleExample 1:Input: str1 = "abac", str2 = "cab"Output: "cabac"Explanatio..