본문 바로가기

728x90
반응형

Algorithm

(55)
1281. Subtract the Product and Sum of Digits of an Integer Description Given an integer number n, return the difference between the product of its digits and the sum of its digits. Example Input: n = 234 Output: 15 Explanation: Product of digits = 2 * 3 * 4 = 24 Sum of digits = 2 + 3 + 4 = 9 Result = 24 - 9 = 15 Solve class Solution: def subtractProductAndSum(self, n: int) -> int: each_list = [] while n > 0: each_list.append(int(n % 10)) n //= 10 each_m..
[regex] Apostrophe 찾기 개요 picoCTF 풀려다 이거 스크립트로 만들어보면 괜찮을 듯 싶던 과정에 삽질했다. 문제 풀고자 했던 문제는 다음과 같이 주어지는 문자열 apostrophe 로 감싸진 단어를 추출하는 것이다. strings1 = "Please md5 hash the text between quotes, excluding the quotes: 'leeches'" strings2 = "Please md5 hash the text between quotes, excluding the quotes: 'a car crash'" strings3 = "Please md5 hash the text between quotes, excluding the quotes: 'Hollywood'" strings4 = "Please md5 h..
[LeetCode] Best Time to Buy and Self Stock 문제 You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. Input: prices = [7,1,5,3,6,4] Output: 5 Explanation: Buy..
[LeetCode] removeElement 문제 Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed. Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elements after removing the duplicates, then the first k eleme..
[LeetCode] Array-partition-i 문제 Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum. Input: nums = [1,4,3,2] Output: 4 Explanation: All possible pairings (ignoring the ordering of elements) are: 1. (1, 4), (2, 3) -> min(1, 4) + min(2, 3) = 1 + 2 = 3 2. (1, 3), (2, 4) -> min(1, 3) + mi..
[BakJoon] 2675, 문자열 반복 문제 문자열 S를 입력받은 후에, 각 문자를 R번 반복해 새 문자열 P를 만든 후 출력하는 프로그램을 작성하시오. 즉, 첫 번째 문자를 R번 반복하고, 두 번째 문자를 R번 반복하는 식으로 P를 만들면 된다. S에는 QR Code "alphanumeric" 문자만 들어있다. QR Code "alphanumeric" 문자는 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\$%*+-./: 이다. 입력 첫째 줄에 테스트 케이스의 개수 T(1 ≤ T ≤ 1,000)가 주어진다. 각 테스트 케이스는 반복 횟수 R(1 ≤ R ≤ 8), 문자열 S가 공백으로 구분되어 주어진다. S의 길이는 적어도 1이며, 20글자를 넘지 않는다. Source import sys total_count = int(sy..
[CodeUp] 6079, 언제까지 더해야 할까? 1, 2, 3 ... 을 계속 더해 나갈 때, 그 합이 입력한 정수(0 ~ 1000) 보다 같거나 작을 때까지만 계속 더하는 프로그램을 작성해보자. 즉, 1부터 n까지 정수를 계속 더해 나간다고 할 때, 어디까지 더해야 입력한 수보다 같거나 커지는 지를 알아보고자 하는 문제이다. 입력 정수 1개가 입력된다. 출력 1, 2, 3, 4, 5 ... 를 순서대로 계속 더해 합을 만들어가다가, 입력된 정수와 같거나 커졌을 때, 마지막에 더한 정수를 출력한다. Solve number = int(input()) _sum = 0 result = 0 for x in range(1, number): if _sum >= number: break if _sum
[LeetCode] Two Sum Description Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. input 값으로 아래와 같이 list와 target이 주어진다. Input: nums = [2,7,11,15], target = 9 output으로는 list에서 두 개의 원소를 뽑아서 더했을 때 targe..

728x90
반응형