https://leetcode.com/problems/divisible-and-non-divisible-sums-difference/description/
Divisible and Non-divisible Sums Difference - LeetCode
Can you solve this real interview question? Divisible and Non-divisible Sums Difference - You are given positive integers n and m. Define two integers, num1 and num2, as follows: * num1: The sum of all integers in the range [1, n] that are not divisible by
leetcode.com
1 2 3 4 5 6 7 | class Solution: def differenceOfSums(self, n: int, m: int) -> int: num2 = [x for x in range(1, n + 1) if x % m ==0] num1 = [x for x in range(1, n + 1) if x % m !=0] return sum(num1) - sum(num2) | cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2706. Buy Two Chocolates (0) | 2024.01.05 |
---|---|
leetcode 2843. Count Symmetric Integers (0) | 2024.01.05 |
leetcode 2974. Minimum Number Game (0) | 2024.01.05 |
leetcode 2643. Row With Maximum Ones (1) | 2024.01.02 |
leetcode 2788. Split Strings by Separator (1) | 2024.01.02 |
댓글