#1931
Painting a Grid With Three Different Colors
specialist · 905 · lc hard +31 · verified · 77.3% accepted · 934 likes · top 88%
Description
Given two integers m and n, count the ways to color an m x n grid with three colors (red, green, blue) such that no two adjacent cells (horizontally or vertically) share the same color.
Return the count modulo 109 + 7.
Example 1:
Input: m = 1, n = 1
Output: 3
Explanation: The three possible colorings are shown in the image above.
Example 2:
Input: m = 1, n = 2
Output: 6
Explanation: The six possible colorings are shown in the image above.
Example 3:
Input: m = 5, n = 5
Output: 580986
Code
1
2
3