0276. Paint Fence
https://leetcode.com/problems/paint-fence
Description
You are painting a fence of n posts with k different colors. You must paint the posts following these rules:
Every post must be painted exactly one color.
There cannot be three or more consecutive posts with the same color.
Given the two integers n and k, return the number of ways you can paint the fence.
Example 1:

Example 2:
Example 3:
Constraints:
1 <= n <= 501 <= k <= 105The testcases are generated such that the answer is in the range
[0, 231 - 1]for the givennandk.
ac
Last updated
Was this helpful?