Solved LeetCode program · 327 of 1,000
#0446 · Arithmetic Slices II - Subsequence
Original English source
Keep a shared nums holding 2, 4, 6, 8, and 10. Keep a shared powers holding 1, 2, 4, 8, and 16. Keep a shared chosen holding 0, 0, 0, 0, and 0. Keep a shared chosenlen of 0. Keep a shared gap of 0. Keep a shared good of 0. Keep a shared total of 0.
To collect from mask (a whole number) with spot (a whole number). If spot is more than 4, return. The flag is bitwise and of mask and item spot of powers. If flag is more than 0, The here is chosenlen, set item here of chosen to item spot of nums, add 1 to chosenlen. Collect from mask with spot plus 1.
To verify from spot (a whole number) with last (a whole number). If spot is more than last, return. The gapnow is item spot of chosen minus item (spot minus 1) of chosen. If gapnow is not gap, set good to 0. Verify from spot plus 1 with last.
To evaluate from mask (a whole number). Set chosenlen to 0. Collect from mask with 0. If chosenlen is at least 3, set gap to item 1 of chosen minus item 0 of chosen. If chosenlen is at least 3, set good to 1. If chosenlen is at least 3, verify from 2 with chosenlen minus 1. If chosenlen is at least 3 and good is 1, add 1 to total.
For every mask from 1 to 31.
Evaluate from mask.
Show total.
Expected stdout
7