Advertisement
Iam_Sandeep

Paint Fences

Apr 22nd, 2022
1,249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. lint code:https://www.lintcode.com/problem/514/description
  2. class Solution:
  3.     """
  4.    @param n: non-negative integer, n posts
  5.    @param k: non-negative integer, k colors
  6.    @return: an integer, the total number of ways
  7.    """
  8.     def num_ways(self, n: int, k: int) -> int:
  9.         if n==1:return k
  10.         same=k
  11.         diff=k*(k-1)
  12.         total=same+diff
  13.         for i in range(3,n+1):
  14.             same=diff*1
  15.             diff=total*(k-1)
  16.             total=same+diff
  17.         return total
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement