[LeetCode] 2698. Find the Punishment Number of an Integer (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명 Given a positive integer n, return the punishment number of n. The punishment number of n is defined as the sum of the squares of all integers i such that:1 The decimal representation of i * i can be partitioned into contiguous substrings such that the sum of the integer values of these substrings equals i. 문제 예제Example 1:Input: n = 10Output: 182Explanation: There are exactly 3 ..
[LeetCode] 1352. Product of the Last K Numbers (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명Design an algorithm that accepts a stream of integers and retrieves the product of the last k integers of the stream. Implement the ProductOfNumbers class:ProductOfNumbers() Initializes the object with an empty stream.void add(int num) Appends the integer num to the stream.int getProduct(int k) Returns the product of the last k numbers in the current list. You can assume that alw..
[LeetCode] 3066. Minimum Operations to Exceed Threshold Value II (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given a 0-indexed integer array nums, and an integer k. In one operation, you will: Take the two smallest integers x and y in nums.Remove x and y from nums.Add min(x, y) * 2 + max(x, y) anywhere in the array. Note that you can only apply the described operation if nums contains at least two elements. nums. Return the minimum number of operations needed so that all element..
[LeetCode] 2342. Max Sum of a Pair With Equal Sum of Digits (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명 You are given a 0-indexed array nums consisting of positive integers. You can choose two indices i and j, such that i != j, and the sum of digits of the number nums[i] is equal to that of nums[j]. Return the maximum value of nums[i] + nums[j] that you can obtain over all possible indices i and j that satisfy the conditions. 문제 예제Example 1:Input: nums = [18,43,36,13,7]Output: 54E..
[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..