AC concise JAVA


  • 0
    A
    public class Solution {
        public int numWays(int n, int k) {
            if (n == 0 || k == 0) return 0;
            int a = 0, b = k;
            for (int i = 2; i <= n; i++) {
                int tmp = a;
                a = b;
                b = (k - 1) * (tmp + b);
            }       
            return a + b; 
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.