cjql / algorithm

https://cjql.github.io/algorithm/
1 stars 1 forks source link

LeetCode_Dynamic: number-of-ways-to-paint-n-3-grid #10

Open cjql opened 4 years ago

cjql commented 4 years ago

https://leetcode.com/problems/number-of-ways-to-paint-n-3-grid/submissions/

C++

Java

Python

class Solution:
    def numOfWays(self, n: int) -> int:
        a123,a121,mod = 6,6,10**9+7
        for i in range(n-1):
            a123,a121 = a121*2+a123*2,a121*3+a123*2
        return (a123+a121) % mod

C

C

JavaScript

Ruby

Swift

Go

Scala

Kotlin

Rust

PHP