nums
in ascending order.answer
to 0 and mod
to 10^9 + 7.nums
and store them in an array power
, taking modulo mod
.left
to 0 and right
to the length of nums
- 1.left
from 0 to the length of nums
- 1:
a. While left
is less than or equal to right
and the sum of nums[left]
and nums[right]
is greater than target
, decrement right
.
b. If left
is less than or equal to right
, add power[right - left]
to answer
(modulo mod
).
c. Increment left
.answer
.