[LeetCode] 1910. Remove All Occurrences of a Substring (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명 Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed:Find the leftmost occurrence of the substring part and remove it from s.Return s after removing all occurrences of part.A substring is a contiguous sequence of characters in a string. 문제 예제Example 1:Input: s = "daabcbaabcbc", part = "abc"Output: "dab"Explana..
[LeetCode] 3174. Clear Digits (Python)
·
알고리즘/LeetCode
난이도: Easy문제 설명 You are given a string s. Your task is to remove all digits by doing this operation repeatedly:Delete the first digit and the closest non-digit character to its left.Return the resulting string after removing all digits. 문제 예제Example 1:Input: s = "abc"Output: "abc"Explanation:There is no digit in the string.Example 2:Input: s = "cb34"Output: ""Explanation:First, we apply the opera..
[LeetCode] 2364. Count Number of Bad Pairs (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given a 0-indexed integer array nums. A pair of indices (i, j) is a bad pair if i and j - i != nums[j] - nums[i].Return the total number of bad pairs in nums. 문제 예제Example 1:Input: nums = [4,1,3,3]Output: 5Explanation: The pair (0, 1) is a bad pair since 1 - 0 != 1 - 4.The pair (0, 2) is a bad pair since 2 - 0 != 3 - 4, 2 != -1.The pair (0, 3) is a bad pair since 3 - 0 !..
[LeetCode] 2349. Design a Number Container System (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명Design a number container system that can do the following:Insert or Replace a number at the given index in the system.Return the smallest index for the given number in the system.Implement the NumberContainers class:NumberContainers() Initializes the number container system.void change(int index, int number) Fills the container at index with the number. If there is already a num..
[LeetCode] 3160. Find the Number of Distinct Colors Among the Balls (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given an integer limit and a 2D array queries of size n x 2. There are limit + 1 balls with distinct labels in the range [0, limit]. Initially, all balls are uncolored. For every query in queries that is of the form [x, y], you mark ball x with the color y. After each query, you need to find the number of distinct colors among the balls. Return an array result of length n..
[LeetCode] 1726. Tuple with Same Product (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명 Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d. 문제 예제Example 1:Input: nums = [2,3,4,6]Output: 8Explanation: There are 8 valid tuples:(2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3)(3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2)Example 2:Input: nums = [..