###### tags: `Weekly Contest` # Weekly Contest 411 ## [3258. Count Substrings That Satisfy K-Constraint I](https://leetcode.com/problems/count-substrings-that-satisfy-k-constraint-i) (<font color=#00B8A3>Easy</font>) 限制 : <ul> <li><code>1 <= s.length <= 50 </code></li> <li><code>1 <= k <= s.length</code></li> <li><code>s[i] is either '0' or '1'</code></li> </ul> ### Solution * 這一題要做的事情是看有多少子序列是符合 0的數量<k 或 1的數量 < k * 簡單解的話就是暴力解。 #### 時間複雜度: $O(N^2)$ #### 空間複雜度: $O(1)$ 程式碼: ```c++= class Solution { public: int countKConstraintSubstrings(string s, int k) { int result = 0; for (int i = 0; i < s.size(); i++) { int max[2] = {}; for (int j = i; j < s.size(); j++) { max[s[j] - '0'] += 1; if (max[0] <= k || max[1] <= k) result++; else break; } } return result; } }; ``` ## [2]() (<font color=#FFC011>Medium</font>) 限制 : <ul> <li><code>10<sup>4</sup></code></li> </ul> ### Solution #### 時間複雜度: $O()$ #### 空間複雜度: $O()$ 程式碼: ```c++= ``` ## [3]()(<font color=#FFC011>Medium</font>) 限制 : <ul> <li><code>10<sup>4</sup></code></li> </ul> ### Solution #### 時間複雜度: $O()$ #### 空間複雜度: $O()$ 程式碼: ```c++= ``` ## [4]()(<font color=#FF375F>Hard</font>) 限制 : <ul> <li><code>10<sup>4</sup></code></li> </ul> ### Solution #### 時間複雜度: $O()$ #### 空間複雜度: $O()$ 程式碼: ```c++= ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up