-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path289.cpp
35 lines (34 loc) · 875 Bytes
/
289.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// 289.cpp
// leetcode
//
// Created by R Z on 2018/4/9.
// Copyright © 2018年 R Z. All rights reserved.
//
#include <stdio.h>
#include <vector>
using namespace std;
class Solution {
public:
void gameOfLife(vector<vector<int>>& board) {
int m=board.size(), n=m?board[0].size():0;
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
int count = 0;
for(int I=max(i-1,0); I<min(i+2,m); I++){
for(int J=max(j-1,0); J<min(j+2,n); J++){
count+=board[I][J]&1;
}
}
if(count==3 || count-board[i][j]==3){
board[i][j] |= 2;
}
}
}
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
board[i][j]>>=1;
}
}
}
};