Leetcode Problem 2177. Find Three Consecutive Integers That Sum to a Given Number

2177. Find Three Consecutive Integers That Sum to a Given Number

Leetcode Solutions

Divide and Check Approach

  1. Check if num is divisible by 3.
  2. If it is not, return an empty array as num cannot be expressed as the sum of three consecutive integers.
  3. If it is divisible, calculate the middle integer x by dividing num by 3.
  4. Return an array containing x-1, x, and x+1.
UML Thumbnail

Iterative Search Approach

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...