Skip to content

2579. Count Total Number of Colored Cells 👍

  • Time: $O(1)$
  • Space: $O(1)$
1
2
3
4
5
6
class Solution {
 public:
  long long coloredCells(int n) {
    return 1LL * n * n + 1LL * (n - 1) * (n - 1);
  }
};
1
2
3
4
5
class Solution {
  public long coloredCells(int n) {
    return 1L * n * n + 1L * (n - 1) * (n - 1);
  }
}
1
2
3
class Solution:
  def coloredCells(self, n: int) -> int:
    return n**2 + (n - 1)**2