We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 85cde5c commit 1fcbeb3Copy full SHA for 1fcbeb3
EASY/src/easy/PaintFence.java
@@ -0,0 +1,15 @@
1
+package easy;
2
+
3
+public class PaintFence {
4
+ public int numWays(int n, int k) {
5
+ if(n == 0) return 0;
6
+ else if(n == 1) return k;
7
+ int sameColorCnt = k, diffColorCnt = k*(k-1);
8
+ for(int i = 2; i < n; i++){
9
+ int temp = diffColorCnt;
10
+ diffColorCnt = (diffColorCnt+sameColorCnt)*(k-1);
11
+ sameColorCnt = temp;
12
+ }
13
+ return sameColorCnt+diffColorCnt;
14
15
+}
0 commit comments