# 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) ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up