본문 바로가기
python-algorithm

leetcode 2652. Sum Multiples

by 무적김두칠 2023. 5. 16.

https://leetcode.com/problems/sum-multiples/description/

 

Sum Multiples - LeetCode

Can you solve this real interview question? Sum Multiples - Given a positive integer n, find the sum of all integers in the range [1, n] inclusive that are divisible by 3, 5, or 7. Return an integer denoting the sum of all numbers in the given range satisf

leetcode.com

 

1
2
3
4
5
6
7
8
class Solution(object):
    def sumOfMultiples(self, n):
        answer = 0
        for num in range(1, n+1):
            if num % 3 == 0 or num % 5 == 0 or num % 7 == 0:
                answer += num
        
        return answer
cs
반응형

댓글