Leetcode Problem 2652. Sum Multiples

2652. Sum Multiples

Leetcode Solutions

Iterative Summation of Divisible Numbers

  1. Initialize sum to 0.
  2. Loop through numbers from 1 to n (inclusive).
  3. For each number i, check if i is divisible by 3, 5, or 7.
  4. If i is divisible by any of these, add i to sum.
  5. After the loop, return sum as the result.
UML Thumbnail

Summation Using Inclusion-Exclusion Principle

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...