2177. Find Three Consecutive Integers That Sum to a Given Number Medium
1/**
2 * [2177] Find Three Consecutive Integers That Sum to a Given Number
3 *
4 * Given an integer num, return three consecutive integers (as a sorted array) that sum to num. If num cannot be expressed as the sum of three consecutive integers, return an empty array.
5 *
6 * Example 1:
7 *
8 * Input: num = 33
9 * Output: [10,11,12]
10 * Explanation: 33 can be expressed as 10 + 11 + 12 = 33.
11 * 10, 11, 12 are 3 consecutive integers, so we return [10, 11, 12].
12 *
13 * Example 2:
14 *
15 * Input: num = 4
16 * Output: []
17 * Explanation: There is no way to express 4 as the sum of 3 consecutive integers.
18 *
19 *
20 * Constraints:
21 *
22 * 0 <= num <= 10^15
23 *
24 */
25pub struct Solution {}
26
27// problem: https://leetcode.com/problems/find-three-consecutive-integers-that-sum-to-a-given-number/
28// discuss: https://leetcode.com/problems/find-three-consecutive-integers-that-sum-to-a-given-number/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32impl Solution {
33 pub fn sum_of_three(num: i64) -> Vec<i64> {
34
35 }
36}
37
38// submission codes end
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn test_2177() {
46 }
47}
48
Back
© 2025 bowen.ge All Rights Reserved.