Leetcode 276 Solution
This article provides solution to leetcode question 276 (paint-fence)
Access this page by simply typing in "lcs 276" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/paint-fence
Solution
class Solution {
public:
int numWays(int n, int k) {
if (n == 0 || k == 0)
return 0;
int diff = k;
int same = 0;
for (int i = 2; i <= n; i++)
{
int tmp = diff;
diff = (same + diff) * (k - 1);
same = tmp;
}
return same + diff;
}
};