leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0289.cpp (722B)


0 class Solution {
1 public:
2 void gameOfLife(vector<vector<int>> &board) {
3 int n = board.size(), m = board[0].size();
4 for (int i = 0; i < n; i++) {
5 for (int j = 0; j < m; j++) {
6 int add = (board[i][j] & 1) << 1;
7 for (int k = max(i - 1, 0); k <= min(n - 1, i + 1); k++) {
8 for (int l = max(j - 1, 0); l <= min(m - 1, j + 1); l++) {
9 board[k][l] += add;
10 }
11 }
12 }
13 }
15 for (int i = 0; i < n; i++) {
16 for (int j = 0; j < m; j++) {
17 board[i][j] = board[i][j] == 7 || board[i][j] == 9 || board[i][j] == 6;
18 }
19 }
20 }
21 };