Find Three Consecutive Integers That Sum to a Given Number – 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.
Find Three Consecutive Integers That Sum to a Given Number solution leetcode
Input: num = 33 Output: [10,11,12] Explanation: 33 can be expressed as 10 + 11 + 12 = 33. 10, 11, 12 are 3 consecutive integers, so we return [10, 11, 12].
Find Three Consecutive Integers That Sum to a Given Number solution leetcode
Input: num = 4 Output: [] Explanation: There is no way to express 4 as the sum of 3 consecutive integers.
Find Three Consecutive Integers That Sum to a Given Number solution leetcode
0 <= num <= 1015
long[] arr = new long[0]; // = new long[3];
//long x =0;
if(num % 3 == 0){
arr = new long[3];
arr[0]=(num/3)-1;arr[1]=num/3;arr[2]=(num/3)+1;//break;
}
return arr;