[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 = [..
[LeetCode] 1790. Check if One String Swap Can Make Strings Equal (Python)
·
알고리즘/LeetCode
난이도: Easy문제 설명You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices. Return true if it is possible to make both strings equal by performing at most one string swap on exactly one of the strings. Otherwise, return false. 문제 예제Example 1:Input: s1 = "bank", s2 =..
[LeetCode] 1800. Maximum Ascending Subarray Sum (Python)
·
카테고리 없음
난이도: Easy문제 설명Given an array of positive integers nums, return the maximum possible sum of an ascending subarray in nums. A subarray is defined as a contiguous sequence of numbers in an array. A subarray [numsl, numsl+1, ..., numsr-1, numsr] is ascending if for all i where l , numsi i+1. Note that a subarray of size 1 is ascending. 문제 예제Example 1:Input: nums = [10,20,30,5,10,50]Output: 65Explan..