2177. Find Three Consecutive Integers That Sum to a Given Number
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 65% Topics: Math, Simulation
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(1)
# Space: O(1)
# math
class Solution(object):
def sumOfThree(self, num):
"""
:type num: int
:rtype: List[int]
"""
return [num//3-1, num//3, num//3+1] if num%3 == 0 else []
Solution from kamyu104/LeetCode-Solutions · MIT