본문 바로가기

python-algorithm1422

codeforces 1742A - Sum https://codeforces.com/problemset/problem/1742/A Problem - 1742A - Codeforces codeforces.com 1 2 3 4 5 6 7 8 9 10 11 12 13 def sol(nums): if sum(nums) - max(nums) == max(nums): return 'YES' else: return 'NO' if __name__ == '__main__': n = int(input()) for _ in range(n): nums = list(map(int, input().split())) print(sol(nums)) Colored by Color Scripter cs 2023. 1. 25.
codeforces 133A - HQ9+ https://codeforces.com/problemset/problem/133/A Problem - 133A - Codeforces codeforces.com 1 2 3 4 5 6 7 8 9 10 11 def sol(s): if 'H' in s or 'Q' in s or '9' in s: return 'YES' else: return 'NO' if __name__ == '__main__': s = input() print(sol(s)) Colored by Color Scripter cs 2023. 1. 25.
codeforces 158A - Next Round https://codeforces.com/problemset/problem/158/A Problem - 158A - Codeforces codeforces.com 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 from bisect import bisect_right, bisect_left def sol(nums, n, k): nums.sort() if nums[-k] != 0: answer = (n - bisect_left(nums, nums[-k])) else: answer = n-nums.count(0) return answer if __name__ == '__main__': n, k = map(int, input().split()) nums = list(map(int, .. 2023. 1. 25.
백준 26560 Periods https://www.acmicpc.net/problem/26560 26560번: Periods Eric gets distracted so sometimes he forgets to put periods at the end of his sentences. To help him out, you are to put a period at the end of his sentences if the period is not already present. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 def sol(s): if s[-1] != '.': return s + '.' else: return s if __name__ == '__main__': n = int(input()).. 2023. 1. 24.
leetcode 1684. Count the Number of Consistent Strings https://leetcode.com/problems/count-the-number-of-consistent-strings/description/ Count the Number of Consistent Strings - LeetCode Count the Number of Consistent Strings - You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed. Return the number of consistent st leetcode... 2023. 1. 22.
leetcode 58. Length of Last Word https://leetcode.com/problems/length-of-last-word/description/ Length of Last Word - LeetCode Length of Last Word - Given a string s consisting of words and spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only. Example 1: Input: s = "Hello World" Output: 5 Explanation: Th leetcode.com 1 2 3 4 class Solution: def lengthOfL.. 2023. 1. 21.
leetcode 2404. Most Frequent Even Element https://leetcode.com/problems/most-frequent-even-element/description/ Most Frequent Even Element - LeetCode Most Frequent Even Element - Given an integer array nums, return the most frequent even element. If there is a tie, return the smallest one. If there is no such element, return -1. Example 1: Input: nums = [0,1,2,2,4,4,1] Output: 2 Explanation: The even leetcode.com 1 2 3 4 5 6 7 8 9 10 11.. 2023. 1. 19.
leetcode 2465. Number of Distinct Averages https://leetcode.com/problems/number-of-distinct-averages/description/ Number of Distinct Averages - LeetCode Number of Distinct Averages - You are given a 0-indexed integer array nums of even length. As long as nums is not empty, you must repetitively: * Find the minimum number in nums and remove it. * Find the maximum number in nums and remove it. * Calculate th leetcode.com 12345678910111213c.. 2023. 1. 19.
leetcode 2496. Maximum Value of a String in an Array https://leetcode.com/problems/maximum-value-of-a-string-in-an-array/description/ Maximum Value of a String in an Array - LeetCode Maximum Value of a String in an Array - The value of an alphanumeric string can be defined as: * The numeric representation of the string in base 10, if it comprises of digits only. * The length of the string, otherwise. Given an array strs of alphanumeric leetcode.co.. 2023. 1. 19.
leetcode 2535. Difference Between Element Sum and Digit Sum of an Array https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array/description/ Difference Between Element Sum and Digit Sum of an Array - LeetCode Can you solve this real interview question? Difference Between Element Sum and Digit Sum of an Array - You are given a positive integer array nums. * The element sum is the sum of all the elements in nums. * The digit sum is the s.. 2023. 1. 17.
leetcode 326. Power of Three https://leetcode.com/problems/power-of-three/description/ Power of Three - LeetCode Power of Three - Given an integer n, return true if it is a power of three. Otherwise, return false. An integer n is a power of three, if there exists an integer x such that n == 3x. Example 1: Input: n = 27 Output: true Explanation: 27 = 33 Example 2: leetcode.com 1 2 3 4 5 6 7 8 9 import math def Log3(x): retur.. 2023. 1. 17.
leetcode 263. Ugly Number https://leetcode.com/problems/ugly-number/description/ Ugly Number - LeetCode Ugly Number - An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. Given an integer n, return true if n is an ugly number. Example 1: Input: n = 6 Output: true Explanation: 6 = 2 × 3 Example 2: Input: n = 1 Output: true leetcode.com 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2.. 2023. 1. 17.