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 |
반응형
'python-algorithm' 카테고리의 다른 글
백준 27890 특별한 작은 분수 (0) | 2023.06.08 |
---|---|
백준 28113 정보섬의 대중교통 (0) | 2023.06.07 |
백준 27959 초코바 (0) | 2023.04.25 |
leetcode 1431. Kids With the Greatest Number of Candies (0) | 2023.04.17 |
백준 27889 특별한 학교 이름 (0) | 2023.04.04 |
댓글