diff --git a/36. Valid Sudoku.cpp b/36. Valid Sudoku.cpp new file mode 100644 index 0000000..b22cfbb --- /dev/null +++ b/36. Valid Sudoku.cpp @@ -0,0 +1,28 @@ +class Solution { +public: + bool isValidSudoku(vector>& board) { + bitset<9> Col[9]; + bitset<9> Row[9]; + bitset<9> Block[9]; + + for(int i = 0; i < 9; i++){ + for(int j = 0; j < 9; j++){ + char c = board[i][j]; + if (c == '.') continue; + int x = (c - '0') % 9; + + if (Row[i][x]) return 0; + Row[i][x] = 1; + + if (Col[j][x]) return 0; + Col[j][x] = 1; + + int bidx = (i / 3) * 3 + j / 3; + + if (Block[bidx][x]) return 0; + Block[bidx][x] = 1; + } + } + return 1; + } +}; \ No newline at end of file diff --git a/Number of People Aware of a Secret.cpp b/Number of People Aware of a Secret.cpp new file mode 100644 index 0000000..6c9a52d --- /dev/null +++ b/Number of People Aware of a Secret.cpp @@ -0,0 +1,19 @@ +class Solution { +public: + int peopleAwareOfSecret(int n, int delay, int forget) { + vector dp(n + 1, 0); + dp[1] = 1; + long long share = 0, MOD = 1000000007; + for (int t = 2; t <= n; t++) { + if (t - delay > 0) + share = (share + dp[t - delay] + MOD) % MOD; + if (t - forget > 0) + share = (share - dp[t - forget] + MOD) % MOD; + dp[t] = share; + } + long long know = 0; + for (int i = n - forget + 1; i <= n; i++) + know = (know + dp[i]) % MOD; + return (int)know; + } +};