# 2579. Count Total Number of Colored Cells ###### tags: `Leetcode` `Medium` `Math` Link: https://leetcode.com/problems/count-total-number-of-colored-cells/description/ ## 思路 找规律 每个图案的colored cells个数是1+3+...+2n-1+2n-3+...+3+1 也就是两个等差数列求和 ``` 1+3+...+2n-1 = n*n 2n-3+...+3+1 = (n-1)*(n-1) ``` ## Code ```python= class Solution: def coloredCells(self, n: int) -> int: return n*n+(n-1)*(n-1) ```