Skip to content

Commit 1fcbeb3

Browse files
EASY/src/easy/PaintFence.java
1 parent 85cde5c commit 1fcbeb3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

‎EASY/src/easy/PaintFence.java

+15
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)