public long numberOfWays(String s) {
char[] array = s.toCharArray();
int n = array.length;
long[][][] dp = new long[2][4][2];
for (int i = 0; i < 2; i++) {
dp[i][0][1] = 1;
dp[i][0][0] = 1;
}
int base = 0;
dp[base][1][array[0] - '0'] = 1;
for (int i = 1; i < n; i++) {
base ^= 1;
for (int j = 1; j < 4; j++) {
dp[base][j][0] = dp[base ^ 1][j][0];
dp[base][j][1] = dp[base ^ 1][j][1];
dp[base][j][array[i] - '0'] += dp[base ^ 1][j - 1][(array[i] - '0') ^ 1];
}
}
return dp[base][3][0] + dp[base][3][1];
}
标签:lc,int,2222,long,++,base,array,dp
From: https://blog.51cto.com/u_14066730/11917630