Solved LeetCode program · 915 of 1,000
#1269 · Number of Ways to Stay in the Same Place After Some Steps
Original English source
The steps is 3, while the places is 2. The reach is the smaller of steps plus 1 and places. The width is reach plus 2. The table is a list of width zeros. The fresh is a list of width zeros. Set item 1 of table to 1.
For every stride from 1 to steps.
For every spot from 1 to reach.
If stride modulo 2 is 1, set item spot of fresh to (item spot of table plus item (spot minus 1) of table plus item (spot plus 1) of table) modulo 1000000007. If stride modulo 2 is 0, set item spot of table to (item spot of fresh plus item (spot minus 1) of fresh plus item (spot plus 1) of fresh) modulo 1000000007.
If steps modulo 2 is 1, show item 1 of fresh, otherwise show item 1 of table.
Expected stdout
4